Welcome to the LimeSurvey Community Forum

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

Multiple numeric input with hidden input fields

  • RHLSA1
  • RHLSA1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 7 months ago - 3 years 7 months ago #205391 by RHLSA1
Dear Forum,

I would like to implement the following question, where one answer option includes a numerical input:

But in the workaround I only found how to hide comments from multiple-choice questions, which worked well for the cases where I needed it:
manual.limesurvey.org/Workarounds:_Quest...comments.22_question

Is there a similar possibility to hide input boxes for multiple numerical input or another way to implement it?

Thanks in advance,
RHLSA1

Version Information:
Version 3.17.7+190627
Last edit: 3 years 7 months ago by RHLSA1.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #205393 by tpartner
I don't see how a multiple numerical would help you. There would be no way to select "No" or "Don't know".

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • RHLSA1
  • RHLSA1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 7 months ago #205395 by RHLSA1
Hi tpartner,
thank you. the idea is that the text you have on the left is still visible, but the input filed not.
so basically:

yes __ 'suffix'
no (__ 'suffix') hidden
don't know (__ 'suffix') hidden
The topic has been locked.
  • RHLSA1
  • RHLSA1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 7 months ago #205397 by RHLSA1
or do you mean that numerical input option can only be checked if i tipe a number in the input field?
so in this case, I can only use a multiple choice with comment, do I understand it right? is there a way to specifiy that a numerical input is required as comment?
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #205410 by holch
This is a typical paper to online issue.

This is a very good case for two questions. Ask yes, no, don't know and if yes, show the question about days per year via relevance equation.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago - 3 years 7 months ago #205411 by tpartner
I would use a multiple-choice-with-comments type question and insert this script which will:

- Remove the second and third text inputs
- Render the text input numeric-only
- Enforce a maximum number of characters for the text input
- Add a suffix for the text input
- Render check-boxes exclusive

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Remove the second and third text inputs
    $('input:text.form-control:gt(0)', thisQuestion).remove();
 
    // Listener on the text input
    $('input:text.form-control', thisQuestion).on('keyup change', function(e) {
      var thisValue = $.trim($(this).val());
 
      // Strip out non-numerics characters
      newValue = thisValue.replace(/\D/g,'').replace(/,/g,'').replace(/\./g,'');
      $(this).val(newValue);
    });
 
    // Size and max characters for the text input
    $('input:text', thisQuestion).attr('size', 3).attr('maxlength', 3);
 
    // Suffix for the text input
    $('input:text', thisQuestion).css({
      'display': 'inline-block',
      'margin-right': '0.5em'
    })
    .after('Tag(e) pro Jahr');
 
    // Render answers exclusive
    $('input:checkbox', thisQuestion).on('change', function(e) {
      if($(this).is(':checked')) {
        var thisRow = $(this).closest('.checkbox-text-item');
        $('.checkbox-text-item', thisQuestion).not(thisRow).each(function(i) {
          console.log(i);
          var thisCheckbox = $('input:checkbox', this);
          var thisText = $('input:text', this);
          $('input:text', this).val('');
          $('input:hidden', this).val('');
          $('input:checkbox', this).prop('checked', false);
        });
      }
    });
    });
</script>



Sample survey attached:

File Attachment:

File Name: limesurvey...5(1).lss
File Size:19 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 7 months ago by tpartner.
The following user(s) said Thank You: VictoriaLawFoundation, RHLSA1
The topic has been locked.
  • RHLSA1
  • RHLSA1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #205724 by RHLSA1
Thanks a lot tpartner, I tried it now and it worked - is there an easy adaption to have the input visible for the first 2 out of 4 answer options? And then also have different suffixes for these input fields?
I tried some variations in line
Code:
$('input:text.form-control:gt(0)', thisQuestion).remove();

but I am unfamiliar with javascript and it did not work.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #205726 by Joffm
Hi,
I can give you an answer.
As you might imagine this line
Code:
$('input:text.form-control:gt(0)', thisQuestion).remove();
means "all controls greater than (gt) 0 are removed".

So you should adapt by saying
Code:
$('input:text.form-control:gt(1)', thisQuestion).remove();

And the same you do with the different suffixes.
Code:
    // Suffix for the text input
$('input:text.form-control:eq(0)', thisQuestion).css({
      'display': 'inline-block',
      'margin-right': '0.5em'
    })
    .after('Suffix der 1. Teilfrage');
$('input:text.form-control:eq(1)', thisQuestion).css({
      'display': 'inline-block',
      'margin-right': '0.5em'
    })
    .after('Suffix der 2. Teilfrage');

Also consider that only existing text inputs are counted.



Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: tpartner, RHLSA1
The topic has been locked.
  • RHLSA1
  • RHLSA1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #205728 by RHLSA1
Thanks a lot also for the explanation Joffm!
So an alternative to gt would be st for smaller than?
And is there a way to combine this, let's say I have 5 options but only the 4th should display an input field?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #205729 by tpartner

So an alternative to gt would be st for smaller than?

No, it would be lt - www.w3schools.com/jquery/jquery_ref_selectors.asp

I have 5 options but only the 4th should display an input field

Code:
$('input:text.form-control:not(:eq(5))', thisQuestion).remove();

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: RHLSA1
The topic has been locked.
  • RHLSA1
  • RHLSA1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #205733 by RHLSA1
Thank you, the link is very useful!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose