Welcome to the LimeSurvey Community Forum

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

issue with "array(text) with drop-down" and "varLengthArray"

  • Joffm
  • Joffm's Avatar Topic Author
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago #242879 by Joffm
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.6.17
Own server or LimeSurvey hosting: own server
Survey theme/template: fruity
==================
I combine the two workarounds to
  • add drop-downs in an array(text)
  • add the dynamic display of rows with "varLengthArray"

Like this:
 

Now if I remove the last row
 

and add a row again, only the text value is removed, but the value of the drop-down is still there.
 

I think there has to be added something to this part of the script, but because of my very limited knowledge of javascript...
Code:
            
function removeRow(qID) {
                var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
                var rowCount = $( arrayRow ).size() - 1;
                $( arrayRow + '[name="visible"]:last input[type="text"]' ).val('');
                $( arrayRow + '[name="visible"]:last' ).attr('name', 'hidden').hide();
                $( 'div#addButton'+qID ).show();
                if ( $( arrayRow + ':eq(1)' ).attr('name') == 'hidden' )  {
                    $( 'div#removeButton'+qID ).hide();
                }
            }

Here the lss export of this example.
 

File Attachment:

File Name: limesurvey...1444.lss
File Size:30 KB


I hope somebody can help.

Thank you in advance
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago #242882 by tpartner
Yup, you are correct - that's the code block to modify.

This should do the trick:

Code:
function removeRow(qID) {
  var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
  var rowCount = $( arrayRow ).size() - 1;
  $( arrayRow + '[name="visible"]:last input[type="text"]' ).val('');
  $( arrayRow + '[name="visible"]:last select' ).val('');
  $( arrayRow + '[name="visible"]:last' ).attr('name', 'hidden').hide();
  $( 'div#addButton'+qID ).show();
  if ( $( arrayRow + ':eq(1)' ).attr('name') == 'hidden' )  {
    $( 'div#removeButton'+qID ).hide();
  }
}

Sample survey attached: 

File Attachment:

File Name: limesurvey...4441.lss
File Size:29 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, LISHANGQI

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose