Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Avoid answer edit in multiple text array

Avoid answer edit in multiple text array 3 years 11 months ago #85445

  • takaite
  • takaite's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
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: 3 years 11 months ago by takaite.
The administrator has disabled public write access.

Avoid answer edit in multiple text array 3 years 11 months ago #85474

  • Ben_V
  • Ben_V's Avatar
  • Offline
  • Platinum Lime
  • Posts: 1805
  • Thank you received: 445
  • Karma: 111
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
All LS releases => bit.ly/1VMuTDu | 2.06lts => bit.ly/1Qv44A1
Demo surveys => bit.ly/20NW9V8 (already included in /docs/demosurveys)
The administrator has disabled public write access.

Avoid answer edit in multiple text array 3 years 11 months ago #85476

  • Mazi
  • Mazi's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5984
  • Thank you received: 368
  • Karma: 260
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)limesurvey.org'"
The administrator has disabled public write access.

Avoid answer edit in multiple text array 3 years 11 months ago #85492

  • takaite
  • takaite's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
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!


  • 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: 3 years 11 months ago by takaite.
    The administrator has disabled public write access.

    Avoid answer edit in multiple text array 3 years 11 months ago #85499

    • Ben_V
    • Ben_V's Avatar
    • Offline
    • Platinum Lime
    • Posts: 1805
    • Thank you received: 445
    • Karma: 111
    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
    All LS releases => bit.ly/1VMuTDu | 2.06lts => bit.ly/1Qv44A1
    Demo surveys => bit.ly/20NW9V8 (already included in /docs/demosurveys)
    Last Edit: 3 years 11 months ago by Ben_V.
    The administrator has disabled public write access.
    Moderators: ITEd
    Time to create page: 0.412 seconds
    Imprint                   Data Protection Statement                  Revocation information and revocation form