Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Conditionally set dropdown list to disabled

  • mcovents
  • mcovents's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 7 months ago #204895 by mcovents
I want to set a dropdown list conditionally to disabled similar to the solution below which works for a text input.
forums.limesurvey.org/forum/can-i-do-thi...on-input-to-disabled

<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:complete',function() {
var lockit = '{DisableThem.NAOK}';
if (lockit == 'Y') {
$("#answer123432X6804X55061").prop('readonly', true);
}
else {
$("#answer123432X6804X55061").prop('readonly', false);
}
});
</script>

How can I update the code to make it work for a dropdown list?
The topic has been locked.
More
3 years 7 months ago #204902 by jelo
You should provide the LimeSurvey version you use. Workarounds often only work in certain versions. You might provide a LSS export of an example survey with just the one question the workaround should be applied too as well.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • mcovents
  • mcovents's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 7 months ago #204903 by mcovents
Replied by mcovents on topic Conditionally set dropdown list to disabled
I work with Limesurvey 3.15.5+181115

In attachment you can find the lss.
If you enter Y in the DisableFields question the two other questions (tekst and lijst) should be disabled.
This is working for the tekst question but not for the lijst question which is of a different type (dropdown)

Thank you for your response,
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #204904 by Joffm
You want to disable the whole question?

Why not use relevance equation (to hide the question)?
DisableFields!="Y"

Or ist there something else you did not mention yet?

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • mcovents
  • mcovents's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 7 months ago #204907 by mcovents
Replied by mcovents on topic Conditionally set dropdown list to disabled
We want the information to remain visible.
The purpose of this is the following.
The survey has to be completed by two persons subsequently.
We want to create an expense report application. The person declaring his expenses fills in the survey. Next the supervisor receives an email with a link to the same survey so he can view the data entered. This supervisor enters a password in the DisableFields question which disables the questions filled in by the first person so he is not able to change the declaration (for example change the amount declared) This password field also unhides an approval question so the supervisor can accept or reject the declaration.
In a third step after approval the first person enters his final expenses.

If we use relevance equation to hide a question the data entered is lost.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago - 3 years 7 months ago #204910 by tpartner
Replied by tpartner on topic Conditionally set dropdown list to disabled
There is no "readonly" property available for select (dropdown) elements.

If you use the "disabled" property, the data will not be recorded.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 7 months ago by tpartner.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • mcovents
  • mcovents's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 7 months ago #204911 by mcovents
Replied by mcovents on topic Conditionally set dropdown list to disabled
Any suggestions?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #204915 by tpartner
Replied by tpartner on topic Conditionally set dropdown list to disabled
Use Javascript or CSS to hide the dropdown, use Expression Script to display its value.

I'm not in a position this week to give detailed examples.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #204927 by DenisChenu
Replied by DenisChenu on topic Conditionally set dropdown list to disabled

tpartner wrote: There is no "readonly" property available for select (dropdown) elements.

If you use the "disabled" property, the data will not be recorded.

Yep,

With dropdown where i need value submitted but need a "readonly" system : i add disabled property at all not selected value :)

It work

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • mcovents
  • mcovents's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 7 months ago #204930 by mcovents
Replied by mcovents on topic Conditionally set dropdown list to disabled
Can you give me example code to disable all not selected values in a dropdown list?
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #205064 by DenisChenu
Replied by DenisChenu on topic Conditionally set dropdown list to disabled
In question text edition,
Something like this
Code:
<script>
$(document).on('ready',function() {
var lockit = '{DisableThem.NAOK}';
    if (lockit == 'Y') {
        var currentValue = $("#answer{SGQ}").val();
        $("#answer{SGQ} select option").each(function() {
            if ( $(this).attr('value') != currentValue) {
                $(this).prop('disabled',true);
            }
        }
    }
});
</script>

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose