- Posts: 10109
- Thank you received: 3595
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
How to create a question with the option to add another line?
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
8 years 6 months ago #126462
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic How to create a question with the option to add another line?
Hmm, that workaround is outdated. Can you please attach a sample exported .lss file containing only your array question and the associated JavaScript?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- DOwen
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 68
- Thank you received: 0
8 years 6 months ago - 8 years 6 months ago #126463
by DOwen
Replied by DOwen on topic How to create a question with the option to add another line?
Hey tpartner, I've uploaded a LSQ file, is this OK? Is there a particular method to follow to send you what you require?
Thanks!
Thanks!
Attachments:
Last edit: 8 years 6 months ago by DOwen.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
8 years 6 months ago - 8 years 6 months ago #126466
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic How to create a question with the option to add another line?
Here is an updated script to apply the expandable array workaround to an array-texts type question in LS 2.06. (You will find this script in the source of the array question in the attached survey below.)
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ variableLengthTextArray({QID}); }) function variableLengthTextArray(qID) { var thisQuestion = $('#question'+qID); thisQuestion.addClass('variable-length-text-array'); // Insert some styles $('<style type="text/css">\ .hidden {\ display: none !important;\ visibility: hidden !important;\ }\ .expandable-control:disabled {\ opacity: 0.3;\ }\ </style>').appendTo('head'); // Insert the controls $('table.subquestions-list', thisQuestion).after('<div class="expandable-controls-wrapper">\ <button type="button" class="expandable-control remove">-</button>\ <button type="button" class="expandable-control add">+</button>\ </div>'); // Click events $('.expandable-control.add', thisQuestion).click(function (event) { $('tr.subquestion-list.hidden:first', thisQuestion).removeClass('hidden').addClass('shown'); handleArrayControls(); $('.expandable-control', thisQuestion).blur(); }); $('.expandable-control.remove', thisQuestion).click(function (event) { $('tr.subquestion-list.shown:last', thisQuestion).removeClass('shown').addClass('hidden'); clearRows(); handleArrayControls(); $('.expandable-control', thisQuestion).blur(); }); function handleArrayControls() { $('.expandable-control.remove', thisQuestion).prop('disabled', true); if($('tr.subquestion-list:visible', thisQuestion).length > 1) { $('.expandable-control.remove', thisQuestion).prop('disabled', false); } $('.expandable-control.add', thisQuestion).prop('disabled', false); if($('tr.subquestion-list:visible', thisQuestion).length == $('tr.subquestion-list', thisQuestion).length) { $('.expandable-control.add', thisQuestion).prop('disabled', true); } } function clearRows() { $('tr.subquestion-list.hidden input:text', thisQuestion).val(''); } // Initially shown rows $('tr.subquestion-list:eq(0)', thisQuestion).addClass('shown'); $('tr.subquestion-list:gt(0)', thisQuestion).addClass('hidden'); $('tr.subquestion-list input:text', thisQuestion).filter(function () {return !!this.value;}).closest('tr.subquestion-list').addClass('answered-row'); var thisQTable = $('table.subquestions-list', thisQuestion); var thisQRows = $('.answered-row', thisQuestion); var lastAnsweredRow = $('.answered-row:last', thisQuestion); var lastAnsweredIndex = $('tr.subquestion-list', thisQTable).index(lastAnsweredRow); $('tr.subquestion-list:lt('+(lastAnsweredIndex+1)+')', thisQuestion).removeClass('hidden').addClass('shown'); handleArrayControls(); } </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 8 years 6 months ago by tpartner.
The following user(s) said Thank You: Ben_V, DOwen
The topic has been locked.
- DOwen
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 68
- Thank you received: 0
8 years 6 months ago #126472
by DOwen
Replied by DOwen on topic How to create a question with the option to add another line?
Oh excellent, thank you Tony! Really useful and appreciate your time putting this together.
At present, it adds just one line at a time. What I need it to do is present all 3 fields (3 fields per product), then when the + button is clicked, another 3 fields will appear to add another product. Have just attempted to solve this myself but looks like I keep breaking it...
At present, it adds just one line at a time. What I need it to do is present all 3 fields (3 fields per product), then when the + button is clicked, another 3 fields will appear to add another product. Have just attempted to solve this myself but looks like I keep breaking it...
The topic has been locked.
- first
- Offline
- Elite Member
Less
More
- Posts: 227
- Thank you received: 36
8 years 6 months ago #126479
by first
Survey Designer and Programmer
Replied by first on topic How to create a question with the option to add another line?
tpartner.. the setup looks just awwwsoooooome:). I also created similar setup in a different programming tool 2 days before but this one is very nice.....I will adapt my code according to yours...
Survey Designer and Programmer
The topic has been locked.
- DOwen
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 68
- Thank you received: 0
8 years 6 months ago #126483
by DOwen
Replied by DOwen on topic How to create a question with the option to add another line?
Hey Tony,
Sorry ignore my previous reply. I had a dull moment! Didn't create the answer fields correctly.
Works great! I was wondering if some array fields can be larger than others? Is this possible? The 'Additional Information' field may need a paragraph of text...
Sorry ignore my previous reply. I had a dull moment! Didn't create the answer fields correctly.
Works great! I was wondering if some array fields can be larger than others? Is this possible? The 'Additional Information' field may need a paragraph of text...
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
8 years 6 months ago #126539
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic How to create a question with the option to add another line?
The only way I see to do that would be to insert following long-text questions and then use JavaScript to move those textareas into the array cells. I don't have time to code that but you may find similar examples in the forum.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- DOwen
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 68
- Thank you received: 0
8 years 6 months ago #126562
by DOwen
Replied by DOwen on topic How to create a question with the option to add another line?
Not sure I'll be able to move anything around with JS myself but ill take a look around and see if I can find anything that might help.
Would it be possible to drop Additional Information (ie, the third and last array field) onto a second row underneath? I also have another question to create which has 5 array fields instead of 3 so it would be good to display these over 2 or more rows...
Would it be possible to drop Additional Information (ie, the third and last array field) onto a second row underneath? I also have another question to create which has 5 array fields instead of 3 so it would be good to display these over 2 or more rows...
The topic has been locked.
- first
- Offline
- Elite Member
Less
More
- Posts: 227
- Thank you received: 36
8 years 6 months ago #126571
by first
Survey Designer and Programmer
Replied by first on topic How to create a question with the option to add another line?
I guess you can consider professional help from Professional parterres
www.limesurvey.com/survey-creation
www.limesurvey.com/survey-creation
Survey Designer and Programmer
The topic has been locked.
- DOwen
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 68
- Thank you received: 0
8 years 6 months ago #126573
by DOwen
Replied by DOwen on topic How to create a question with the option to add another line?
It would be a shame to have to pay anyone as we've managed to achieve a lot so far thanks to help from the forum and self-teaching!
The topic has been locked.
- DOwen
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 68
- Thank you received: 0
8 years 6 months ago - 8 years 6 months ago #126577
by DOwen
Replied by DOwen on topic How to create a question with the option to add another line?
Just to expand on this, I have been asked to try and build a question(s) that work as follows...
We would like the user to add items, in a similar fashion as above, by selecting an item from a drop down list, but then once the product is selected, a list of about 25 questions (different questions per product type) will appear asking finer details on that particular product. I'm envisioning achieving this via a normal dropdown question with a condition set to show all relevant 25 questions underneath when a particular product type is selected.
It would be great to have the same 'Add Another Product' button working on a group of questions.
The problem with this however is adding additional products. I'm struggling to think of a solution. Can anyone please help or advise?
We would like the user to add items, in a similar fashion as above, by selecting an item from a drop down list, but then once the product is selected, a list of about 25 questions (different questions per product type) will appear asking finer details on that particular product. I'm envisioning achieving this via a normal dropdown question with a condition set to show all relevant 25 questions underneath when a particular product type is selected.
It would be great to have the same 'Add Another Product' button working on a group of questions.
The problem with this however is adding additional products. I'm struggling to think of a solution. Can anyone please help or advise?
Last edit: 8 years 6 months ago by DOwen.
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11661
- Thank you received: 2742
8 years 6 months ago #126583
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic How to create a question with the option to add another line?
I think with 25 different questions the normal (+) approach doesn't make sense.
I would create a group for each product including all 25 questions and then at the end I would include a question that asks if they want to add another product. The next question group will only be shown if this question has been answered with yes.
You will need a new page anyway, in my opinion. If there are so many different questions per product.
I would create a group for each product including all 25 questions and then at the end I would include a question that asks if they want to add another product. The next question group will only be shown if this question has been answered with yes.
You will need a new page anyway, in my opinion. If there are so many different questions per product.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The following user(s) said Thank You: DOwen
The topic has been locked.