Prevent editing of text field

More
1 month 3 days ago #192650 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! :)

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
1 month 3 days ago #192655 by Joffm
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.

File Attachment:

File Name: limesurvey...7655.lss
File Size:17 KB


Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The following user(s) said Thank You: ch123

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #192663 by tpartner
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:

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

<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.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: ch123

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #192666 by Joffm
Replied by Joffm on topic Prevent editing of text field

My solution, as usual, includes JavaScript

:lol: :lol: :lol:

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in or Create an account to join the conversation.

More
1 month 2 days 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 :D

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!