- Posts: 44
- Thank you received: 3
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Prevent editing of text field
- ch123
- Topic Author
- Offline
- Senior Member
Less
More
4 years 2 months ago #192650
by ch123
Prevent editing of text field was created by ch123
Hey. Again me with another question
My survey has a short explanation text and on this basis first an open text field and then several single choice questions. Sometimes the single choice questions repeat a part of the open text question. That's why I want to prevent participants from editing their written text.
My ideas to do it:
1) Disable the previous button. Found this thread and it worked. But of course with it it's not possible to go back to other parts of the survey (as this text comprehension task is just a short part of the whole survey). So is it possible with this js-code to skip the page with the text field, but still go further back to the other parts?
2) Prevent editing the text field with grey out or something. So after validating the answer with pressing "next" it shouldn't be possible to do any changes...
Is it possible to do this?
Thanks in advance!
My survey has a short explanation text and on this basis first an open text field and then several single choice questions. Sometimes the single choice questions repeat a part of the open text question. That's why I want to prevent participants from editing their written text.
My ideas to do it:
1) Disable the previous button. Found this thread and it worked. But of course with it it's not possible to go back to other parts of the survey (as this text comprehension task is just a short part of the whole survey). So is it possible with this js-code to skip the page with the text field, but still go further back to the other parts?
2) Prevent editing the text field with grey out or something. So after validating the answer with pressing "next" it shouldn't be possible to do any changes...
Is it possible to do this?
Thanks in advance!
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12790
- Thank you received: 3940
4 years 2 months ago #192655
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Prevent editing of text field
Hi,
my idea is - as usual only with built-in functions - to store the entered text in a hidden question of the same type.
1. There is the question "Open1"
2. create a hidden question of the same type "Open2"
Now create two hidden equations:
3. Store the value of "Open1" into "Open2", BUT ONLY if "Open2" is still empty.
Equation: {Open2=if(is_empty(Open2),Open1,Open2)}
4. Restore "Open2" into "Open1"
Equation: {Open1=Open2}
So, if "Open1" was changed, the "old" value is entered again.
Example. You will see, the first entered text doesn't change.
Joffm
my idea is - as usual only with built-in functions - to store the entered text in a hidden question of the same type.
1. There is the question "Open1"
2. create a hidden question of the same type "Open2"
Now create two hidden equations:
3. Store the value of "Open1" into "Open2", BUT ONLY if "Open2" is still empty.
Equation: {Open2=if(is_empty(Open2),Open1,Open2)}
4. Restore "Open2" into "Open1"
Equation: {Open1=Open2}
So, if "Open1" was changed, the "old" value is entered again.
Example. You will see, the first entered text doesn't change.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: ch123
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
4 years 2 months ago #192663
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Prevent editing of text field
My solution, as usual, includes JavaScript.
On page load, if the text element is not empty, disable it.
For a long-text question, something like this in the question source:
For a short-text question, something like this in the question source:
On page load, if the text element is not empty, disable it.
For a long-text question, something like this in the question source:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ if($.trim($('#question{QID} textarea:eq(0)').val()) != '') { $('#question{QID} textarea:eq(0)').prop('readonly', true); } }); </script>
For a short-text question, something like this in the question source:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ if($.trim($('#question{QID} input:text:eq(0)').val()) != '') { $('#question{QID} input:text:eq(0)').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: ch123
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12790
- Thank you received: 3940
4 years 2 months ago #192666
by Joffm
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Prevent editing of text field
:lol: :lol: :lol:My solution, as usual, includes JavaScript
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- ch123
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 44
- Thank you received: 3
4 years 2 months ago #192675
by ch123
Replied by ch123 on topic Prevent editing of text field
Both solutions are awesome - thanks a lot, Joffm & tpartner!
Now I have to decide which one works better for me
Now I have to decide which one works better for me
The topic has been locked.