Welcome to the LimeSurvey Community Forum

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

List with numerical input

More
7 years 6 months ago #164991 by vzyldd
Is it possible to add the following question in the format indicated:




I need to limit the input of the value of choice number 1 to a maximum of 100 and option 2 do not require any numerical value only a choice if the respondent does not know the % in option 1. What format can I use as the Numerical Input question format will also give me an input block at option 2.

Somewhat in the dark with this.

Thx
The topic has been locked.
More
7 years 6 months ago #164995 by Joffm
Replied by Joffm on topic List with numerical input
Hi, first: which version?

I could offer two ideas for version 2.6x, 2.7x



Here you see three input fields, but of course you can reduce to just one.
It's a script tpartner provided.

Or this



Here a plugin "checkboxfortext" is used which needs another plugin "toolsDOMdocument".

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
More
7 years 6 months ago #164996 by vzyldd
Replied by vzyldd on topic List with numerical input
That would be perfect. Running v2.6
The topic has been locked.
More
7 years 6 months ago #164997 by Joffm
Replied by Joffm on topic List with numerical input
What is 2.6?
Is it the 2.6 lts? Or one of the 2.50 - 2.74 branch?

And which of the two do you prefer?

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
More
7 years 6 months ago #165000 by vzyldd
Replied by vzyldd on topic List with numerical input
My apologies. Version 2.06+ (150831). Would prefer the first option if it will work on my version.
The topic has been locked.
More
7 years 6 months ago - 7 years 6 months ago #165009 by Joffm
Replied by Joffm on topic List with numerical input
Hi, in 2.6+ I get the following.

It is Tony's script and in 2.6+ the listener don't work.
But here you get something to start with: (Template: default)


And here the script:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){  
 
    // Identify this question
    var qID = {QID};
    var thisQuestion = $('#question'+qID);
 
    // Add some classes
    $(thisQuestion).addClass('with-exclusive-items');
    $('td.answer-item', thisQuestion).addClass('non-exclusive-item');
 
    // Loop through the last-column cells
    $('td.answer-item:last-child', thisQuestion).each(function(i) {
      varThisID = $('input[type="text"]', this).attr('id');
 
      // Add a class
      $(this).removeClass('non-exclusive-item').addClass('exclusive-item');
 
      // Hide the text input
      $('td.answer-item:last-child input[type="text"]', thisQuestion).hide();
 
      // Insert checkboxes
      $(this).append('<div class="checkbox">\
                <input class="checkbox" name="" id="'+varThisID+'_cbox" value="N/A" type="checkbox">\
                <label for="'+varThisID+'_cbox" class="answertext inserted-label"></label>\
              </div>'); 
    });
 
    // Listener on the checkboxes
    $('.exclusive-item input[type="checkbox"]', thisQuestion).on('change', function(e) {
      var thisRow = $(this).closest('tr.subquestion-list');
      var thisCell = $(this).closest('td.answer-item');
      if($(this).is(':checked')) {
        $('input[type="text"]', thisCell).val('1');
        $('.non-exclusive-item input[type="text"]', thisRow).val('');
      }
      else {
        $('input[type="text"]', thisCell).val('');
      }
 
      // Fire Expression Manager
      $('input[type="text"]', thisRow).each(function(i) {
        $(this).trigger('keyup');
      });
    });
 
    // Listener on the text inputs
    $('.non-exclusive-item input[type="text"]', thisQuestion).on('keyup change', function(e) {
      var thisRow = $(this).closest('tr.subquestion-list');
      if($.trim($(this).val()) != '') {
        $('.exclusive-item input[type="checkbox"]', thisRow).prop('checked',false);
        $('.exclusive-item input[type="text"]', thisRow).val('');
      }
 
      // Fire Expression Manager
      $('.exclusive-item input[type="text"]', thisRow).trigger('keyup');
    });
 
    // Insert some styles (these could be in template.css)
    // For the LS 2.67 default template
/*
    var newStyles = '.with-exclusive-items thead th.answertext {\
              text-align: center;\
            }\
            .with-exclusive-items .exclusive-item {\
              text-align: center;\
              vertical-align: middle;\
              cursor: pointer;\
            }\
            .with-exclusive-items .checkbox {\
              padding-left: 0;\
            }\
            .with-exclusive-items .inserted-label {\
              width: 24px;\
              min-height: 24px;\
              padding: 0;\
            }\
            .with-exclusive-items .inserted-label::before {\
              margin: 4px 0 0 4px;\
            }\
            .with-exclusive-items .inserted-label::after {\
              margin: 4px 0 0 4px;\
            }';  
*/
//    $('head').append('<style type="text/css">'+newStyles+'</style>');  
  });  
</script>

Maybe ou can adapt it by yourself or someone else here.


Just to add:
It's an array(numbers)



Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 7 years 6 months ago by Joffm.
The following user(s) said Thank You: tpartner, vzyldd
The topic has been locked.
More
7 years 6 months ago #165014 by tpartner
Replied by tpartner on topic List with numerical input
This will get the listeners to work in 2.06:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){  
 
    // Identify this question
    var qID = {QID};
    var thisQuestion = $('#question'+qID);
 
    // Add some classes
    $(thisQuestion).addClass('with-exclusive-items');
    $('td.answer-item', thisQuestion).addClass('non-exclusive-item');
 
    // Loop through the last-column cells
    $('td.answer-item:last-child', thisQuestion).each(function(i) {
      varThisID = $('input[type="text"]', this).attr('id');
 
      // Add a class
      $(this).removeClass('non-exclusive-item').addClass('exclusive-item');
 
      // Hide the text input
      $('td.answer-item:last-child input[type="text"]', thisQuestion).hide();
 
      // Insert checkboxes
      $(this).append('<div class="checkbox">\
                <input class="checkbox" name="" id="'+varThisID+'_cbox" value="N/A" type="checkbox">\
                <label for="'+varThisID+'_cbox" class="answertext inserted-label"></label>\
              </div>'); 
    });
 
    // Listener on the checkboxes
    $('.exclusive-item input[type="checkbox"]', thisQuestion).on('change', function(e) {
      var thisRow = $(this).closest('tr.subquestions-list');
      var thisCell = $(this).closest('td.answer-item');
      if($(this).is(':checked')) {
        $('input[type="text"]', thisCell).val('1');
        $('.non-exclusive-item input[type="text"]', thisRow).val('');
      }
      else {
        $('input[type="text"]', thisCell).val('');
      }
 
      // Fire Expression Manager
      $('input[type="text"]', thisRow).each(function(i) {
        $(this).trigger('keyup');
      });
    });
 
    // Listener on the text inputs
    $('.non-exclusive-item input[type="text"]', thisQuestion).on('keyup change', function(e) {
      var thisRow = $(this).closest('tr.subquestions-list');
      if($.trim($(this).val()) != '') {
        $('.exclusive-item input[type="checkbox"]', thisRow).prop('checked',false);
        $('.exclusive-item input[type="text"]', thisRow).val('');
      }
 
      // Fire Expression Manager
      $('.exclusive-item input[type="text"]', thisRow).trigger('keyup');
    });
  });  
</script>

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
The topic has been locked.
More
7 years 6 months ago #165036 by vzyldd
Replied by vzyldd on topic List with numerical input
Very big thank you. Solved my problem.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose