Welcome to the LimeSurvey Community Forum

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

Conditionally set question input to disabled?

  • blocka
  • blocka's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
6 years 2 months ago - 6 years 2 months ago #162287 by blocka
I have a survey where I pass a URL Parameter called "DisableThem" to the first question in my survey (where value is either Y or empty).


If DisableThem = "Y", I'd like to set several short text response fields to disabled -- so that the values cannot be editted (this is because several questions are also prepopulated with parameters passed to the survey under some conditions.

I still want to show these questions and the response values, but I don't want the participant to be able to edit the responses.

I'm thinking some javascript to check the value of DisableThem and then jquery to change the question input to disabled could work, but I'm not sure how to do this.

Is it possible?

Something like this, but it's not working, so I'm doing something wrong:
Code:
<script>
jQuery(document).ready(
function(){
   var lockit = '{DisableThem.NAOK}';
   if (lockit) == 'Y' {
       document.getElementById("answer458485X809X13701").readOnly=true;
       } else {
       document.getElementById("answer458485X809X13701").readOnly=false;
       }
     }
);
</script>
Last edit: 6 years 2 months ago by blocka. Reason: Adding JS
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago #162292 by tpartner
Replied by tpartner on topic Conditionally set question input to disabled?
Try this:

Code:
<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>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 3 months ago #178408 by tpervaiz
Replied by tpervaiz on topic Conditionally set question input to disabled?
How can I just disable short text so user cannot edit
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 3 months ago #178448 by tpartner
Replied by tpartner on topic Conditionally set question input to disabled?
Place something like this in the source of the question:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:complete',function() {
    $('#question{QID} input:text').prop('readonly', true);
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: tpervaiz
The topic has been locked.
More
5 years 3 months ago #178458 by tpervaiz
Replied by tpervaiz on topic Conditionally set question input to disabled?
Its working perfectly...thanks
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 3 months ago #178459 by DenisChenu
Replied by DenisChenu on topic Conditionally set question input to disabled?
Plugin solution : (using expression now (with 3.9.X and up)
gitlab.com/SondagesPro/QuestionSettingsType/answersAsReadonly

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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 3 months ago #178462 by tpartner
Replied by tpartner on topic Conditionally set question input to disabled?
You could also do it with a custom question theme.

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
5 years 3 months ago #178465 by DenisChenu
Replied by DenisChenu on topic Conditionally set question input to disabled?

tpartner wrote: You could also do it with a custom question theme.

Question theme ?

Or survey theme ?

You're right about survey theme, but don't have an easy way to update it : put a global class using an expression {if(MyCondition," answer-disable","")}

And in css
.answer-disable .answer-item {
pointer-events: none;
cursor: not-allowed;
}

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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 3 months ago - 5 years 3 months ago #178466 by tpartner
Replied by tpartner on topic Conditionally set question input to disabled?
Question theme - like browserdetect

Code:
<input
    class="form-control {{kpclass}}"
    type="text"
    name="{{name}}"
    id="answer{{name}}"
    value="{{dispVal}}"
    {% if inputsize is not empty %} size="{{inputsize}}" {% endif %}
    {% if maxlength is not empty %} maxlength='{{maxlength}}' {% endif %}
    readonly="readonly"
    aria-labelledby="ls-question-text-{{basename}}"
/>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 3 months ago by tpartner.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 3 months ago #178467 by DenisChenu
Replied by DenisChenu on topic Conditionally set question input to disabled?
Yes :)

Then only for "long text question" ;)

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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 3 months ago #178471 by tpartner
Replied by tpartner on topic Conditionally set question input to disabled?
Huh? tpervaiz asked about a short-text question which is what browserdetect is.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose