Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Deselect click in Array

  • simatz
  • simatz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 8 months ago - 4 years 8 months ago #194847 by simatz
Deselect click in Array was created by simatz
Hello, my array is not mandatory.

It means that I give the choice not to answer a certain subquestion.

But I got a problem and could not find in the manual how to solve it.

If I click on a certain subquestion a specific answer and than i regret and I don't want to answer this sub question at all I can not deselect my click.

What can I do?
Thanks
Sima
Last edit: 4 years 8 months ago by simatz.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #194854 by tpartner
Replied by tpartner on topic Deselect click in Array
By definition, you cannot de-select a radio input without selecting another associated radio.

The simple solution is to add a "No answer" option in the array answers

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: simatz
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #194855 by Joffm
Replied by Joffm on topic Deselect click in Array
This is the behaviour of this type (therefore they are called "radio buttons").

Well, I adapted an old script of tpartner.
www.limesurvey.org/forum/can-i-do-this-w...utton-and-javascript
Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function(){
 
    addQuestionReset('{QID}');
 
    function addQuestionReset(qID) {
      var thisQuestion = $('#question'+qID+'');
 
      $('table.subquestion-list', thisQuestion).after('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
 
      $('#question'+qID+' .resetQuestionButton').click(function(e){
        $('input[type="radio"]', thisQuestion).prop('checked', false);
      });
    }
  });  
</script>

This resets the whole array. Maybe tpartner will provide something the works only for one row.



After clicking "Reset"


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: simatz
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #194920 by tpartner
Replied by tpartner on topic Deselect click in Array
Here is a quick solution to insert a reset button for each row:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){  
 
    var thisQuestion = $('#question{QID}');
 
    // Insert the reset buttons
    $('table.subquestion-list .answertext', thisQuestion).append('<div><button type="button" class="btn btn-sm btn-primary inserted-reset">Reset row</button></div>');
 
    // Listener on the reset buttons
    $('.inserted-reset', thisQuestion).on('click', function(e) {
      var thisRow = $(this).closest('tr');
      $('input:radio', thisRow).prop('checked', false);
      checkconditions('', $('input:radio:eq(0)', thisRow).attr('name'), 'radio');
    });
    });
</script>



Sample survey attached:

File Attachment:

File Name: limesurvey...3-04.lss
File Size:45 KB

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: Joffm, simatz
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose