Avoid answer edit in multiple text array

More
4 years 6 months ago - 4 years 6 months ago #85445 by takaite
Hello all;

Sorry by the simple question, but I'm a noob in LimeSurvey.

I'm doing a survey that need to present the last 2 answer of the client (answer gave in the last years) and the client will give a value to this year.

To do that, I'm using a "array (text)", something like this:
<pre>
2010 2011 2012
Question 1 (1) (2) ( )
Question 2 (1) (2) ( )
Question 3 (1) (2) ( )
</pre>
The point is: The client can't edit the last answer. Is it possible to block the fields?
Last Edit: 4 years 6 months ago by takaite.

Please Log in to join the conversation.

More
4 years 6 months ago #85474 by Ben_V
Hi
Adapt the SGQA code and place the script in the help field of the question
<script charset="utf-8" type="text/javascript">
// Place this code into help textarea
$('#answer123X456X789option_cde').attr( "readonly","readonly" );
</script>
Ben/

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)

Please Log in to join the conversation.

More
4 years 6 months ago #85476 by Mazi
Hi Ben,
this example on how to make certain fields uneditable might be very helpful for others as well. Maybe youn can extend it to radio buttons and check boxes and add an example at docs.limesurvey.org/Workarounds%3A+Manip...tions+for+LimeSurvey

Thanks!


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
4 years 6 months ago - 4 years 6 months ago #85492 by takaite
Tks Ben, your trick was excellent!

As a noob, I had some difficulties to make it work, and I'll share here what I did:

  1. In "global settings->security" I'd disabled "Filter HTML for XSS:"
  2. In the preview of the question I got the id of the field to be set;
  3. Edited the question and into the "Question" field or the "help" field I inserted the code bellow:
  <script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		document.getElementById("answer56793X1X5SQ001_SQ001").readOnly=true;
	});
  </script>
  • Save and test!
  • [/ol]

    Again, tks Ben and Mazi to show me the path!
    BR
    Taka

    Some references:
    docs.limesurvey.org/Workarounds%3A+Manip...n_to_this_Wiki_page_
    docs.limesurvey.org/Workarounds%3A+Manip...stom_onload_function
    Last Edit: 4 years 6 months ago by takaite.

    Please Log in to join the conversation.

    More
    4 years 6 months ago - 4 years 6 months ago #85499 by Ben_V
    Hi Guys,
    as pointed by Taka a way to set text (or numeric) input boxes & textareas "readonly" is already available in the wiki
    document.getElementById("answer{SGQ}").readOnly=true;
    2 things:
    - the code of the wiki is better because you can paste it either into the source of the question or help.
    - the code I have indicated first can be easily adapted to change or add any attributes into inputs, textareas, etc…(have to be pasted into the help box)
    <script charset="utf-8" type="text/javascript">
     $('#answer{SGQ}').attr( "value","MyDefaultValue" );
     $('#answer{SGQ}').attr( "style","background:#f55;color:#fff" );
     $('#answer{SGQ}').attr( "readonly","readonly" );
    </script>

    Ben/

    Benoît

    EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
    Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
    Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
    Last Edit: 4 years 6 months ago by Ben_V.

    Please Log in to join the conversation.