Welcome, Guest
Username: Password: Remember me

TOPIC: Avoid answer edit in multiple text array

Avoid answer edit in multiple text array 1 year 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: 1 year 11 months ago by takaite.
The administrator has disabled public write access.

Re: Avoid answer edit in multiple text array 1 year 11 months ago #85474

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1067
  • Thank you received: 235
  • Karma: 74
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

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
The administrator has disabled public write access.

Re: Avoid answer edit in multiple text array 1 year 11 months ago #85476

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 293
  • Karma: 248
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.

Re: Avoid answer edit in multiple text array 1 year 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: 1 year 11 months ago by takaite.
    The administrator has disabled public write access.

    Re: Avoid answer edit in multiple text array 1 year 11 months ago #85499

    • Ben_V
    • Ben_V's Avatar
    • OFFLINE
    • Platinum Lime
    • Posts: 1067
    • Thank you received: 235
    • Karma: 74
    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

    goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
    goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
    goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
    Last Edit: 1 year 11 months ago by Ben_V.
    The administrator has disabled public write access.
    Moderators: ITEd
    Time to create page: 0.125 seconds
    Donation Image