Welcome to the LimeSurvey Community Forum

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

Adding textbox in basic array

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #166917 by tpartner
Replied by tpartner on topic Adding textbox in basic array
Holch, can you activate a test survey?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago - 6 years 8 months ago #166918 by holch
Replied by holch on topic Adding textbox in basic array
Here you go: [link removed as issue is solved]

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

Last edit: 6 years 8 months ago by holch.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #166920 by tpartner
Replied by tpartner on topic Adding textbox in basic array
I see the problem - it's because it's a new version so both the group and the question have an ID of "1".

Change this line:
Code:
var thisCode = $(this).attr('id').split('X'+q1ID)[1];

To this:
Code:
var thisCode = $(this).attr('id').split('X')[2].split(q1ID)[1];

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: holch
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #166921 by tpartner
Replied by tpartner on topic Adding textbox in basic array
... I have edited the code snippet in that post accordingly and uploaded a new sample survey.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #166939 by holch
Replied by holch on topic Adding textbox in basic array
Thanks Tpartner, importing the new version works for me now. But based on your comment, so would a second import of the first version, because the problem would only appear if it was the first survey ever in a new installation, right? Chances that this happens are pretty low I guess, yet I managed to break it. ;-)

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.
More
6 years 8 months ago #166951 by jelo
Replied by jelo on topic Adding textbox in basic array

holch wrote: because the problem would only appear if it was the first survey ever in a new installation, right?

Tpartner mentioned group and question id. No survey id. I don't understand the releation to a new installation and the first survey on such a installtion?

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #166955 by tpartner
Replied by tpartner on topic Adding textbox in basic array
My original code was trying to split the SGQA by the question ID to detect the sub-question ID. Since this is the first group and question in Holch's install, both the group and question IDs are "1", therefor the SGQA gets split at the group ID giving an incorrect result. The solution is to first split the SGQA by the second "X" and then split by the question ID.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
6 years 8 months ago #166958 by jelo
Replied by jelo on topic Adding textbox in basic array

tpartner wrote: Since this is the first group and question in Holch's install, both the group and question IDs are "1",

I thought when creating a new survey gid starts for every survey with one. Which isn't the case as I learned today ;-) Created a new survey on demo.limesurvey.org and got GID 74 and QID 2222 on the first question. Thanks.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • krosser
  • krosser's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 8 months ago #166964 by krosser
Replied by krosser on topic Adding textbox in basic array
Thank you very much Toni for your suggestion and the JS code! Yes, that is reasonable to have it like this.

I wanted to try it but there is a weird system issue with LimeSurvey at the moment - I cannot change themes in the editor, as the save button isn't active (it's in my both personal and corporate accounts). So cannot add anything or remove from custom.css nor custom.js.
I've written to the support about this.
It might be related to their recent update to the buttons by adding an extend button next to each theme.

I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
  • krosser
  • krosser's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 8 months ago - 6 years 8 months ago #166966 by krosser
Replied by krosser on topic Adding textbox in basic array
Tony, I also have similar questions but with an array (Numbers) with checkboxes.



Would it need "checkbox-item input" to be added to the JS code? Your help would be much appreciated.

I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Last edit: 6 years 8 months ago by krosser.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago - 6 years 8 months ago #167015 by tpartner
Replied by tpartner on topic Adding textbox in basic array
For array-numbers-checkboxes...

Place a multiple-short-text question directly after the array. This question should have exactly the same sub-questions as the array y-scale.

Give the array question a CSS class "with-checkbox-array-comments".

Add this to custom.js:

Code:
$(document).on('ready pjax:scriptcomplete',function(){
  // Apply the plugin to specific arrays
  $('.array-multi-flexi.with-checkbox-array-comments').cbArrayComments();
});
 
// A jQuery plugin insert comments into checkbox arrays
(function( $ ){
 
  $.fn.cbArrayComments = function(options) {  
 
    var opts = $.extend( {
    }, options);
 
    return this.each(function() { 
 
      // Identify the questions
      var thisQuestion = $(this);
      var q1ID = $(thisQuestion).attr('id').replace(/question/, '');
      var thisQuestion = $('#question'+q1ID);
      var nextQuestion = thisQuestion.nextAll('.multiple-short-txt:eq(0)');
      var q2ID = $(nextQuestion).attr('id').replace(/question/, '');
 
      //Hide the multiple-short-text
      nextQuestion.hide();
 
      // Move the text inputs
      $('tr.subquestion-list', thisQuestion).each(function(i) {
        var thisCode = $(this).attr('id').split('X')[2].split(q1ID)[1];
        $('td.answer-item:last input[type="checkbox"]', this).css({
          'position': 'absolute',
          'left': '-9999em'
        });
        $('td.answer-item:last', this).removeClass('checkbox-item').addClass('inserted-text-item').append($('input[type="text"][id$="X'+q2ID+thisCode+'"]', nextQuestion));
      });
 
      // Listeners on the text inputs
      $('input[type="text"]', thisQuestion).on('keyup change', function(e) {
        var thisCheckbox = $(this).closest('td').find('input[type="checkbox"]');
        if($.trim($(this).val()) != '') {
          $(thisCheckbox).prop('checked', true);
          $(thisCheckbox).prev('input:hidden').val(1);
        }
        else {
          $(thisCheckbox).prop('checked', false);
          $(thisCheckbox).prev('input:hidden').val('');
        }
        // Fire Expression manager
        $(thisCheckbox).trigger('change');
      });
    });
 
  };
})( jQuery );


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 8 months ago by tpartner.
The following user(s) said Thank You: krosser
The topic has been locked.
  • krosser
  • krosser's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 8 months ago #167039 by krosser
Replied by krosser on topic Adding textbox in basic array
This is amazing, Tony! Many thanks!!

Today, the guys at LimeSurvey have fixed the issue with the Template editor and I could finally test your JS codes by adding to custom.js. They both worked nicely!
I realized that I have to place a Multiple short text question after each Array question that I need to adjust (for example, I have two of this kind of questions in a section).

I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose