- Posts: 68
- Thank you received: 0
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?
- DOwen
- Topic Author
- Offline
- Senior Member
Less
More
8 years 5 months ago - 8 years 5 months ago #126310
by DOwen
Replied by DOwen on topic How to create a question with the option to add another line?
Sorry guys! Our server is internally accessible only. I've contacted the IT administrator to make it public, will let you know when its accessible.
Also, the plus and minus buttons mysteriously appeared. However they do not bring up new array text fields.
Thanks!
Also, the plus and minus buttons mysteriously appeared. However they do not bring up new array text fields.
Thanks!
Last edit: 8 years 5 months ago by DOwen.
The topic has been locked.
- DOwen
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 68
- Thank you received: 0
8 years 5 months ago #126343
by DOwen
Replied by DOwen on topic How to create a question with the option to add another line?
Hi guys,
The survey should now be public so you can check it out. (May take 10 mins as of this email)
Link here
Thanks!
The survey should now be public so you can check it out. (May take 10 mins as of this email)
Link here
Thanks!
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
8 years 5 months ago #126348
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic How to create a question with the option to add another line?
Another more basic approach is the use of a multiple-opt (not mandatory) question with just one option "Add another product" with the related checkbox (check/uncheck)
Remember that you can style this question with CSS and/or javascript
Try-it, pasting the following code in the help area of the question....
Remember that you can style this question with CSS and/or javascript
Try-it, pasting the following code in the help area of the question....
Code:
<script type="text/javascript"> $(document).ready(function() { $( "<style type='text/css'>" + "#question{QID} { border:none; font-size:120%}" +"</style>").appendTo( "head" ); }); </script>
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
8 years 5 months ago #126354
by Mazi
Check the JS and compare the elements it deals with step by step. I assume due to different HTML elements the script doesn't trigger the correct elements.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic How to create a question with the option to add another line?
Though there are no JavaScript errors the structure of your survey HTML seems to differ so the JavaScript can't access the needed elements.DOwen wrote: The survey should now be public so you can check it out. (May take 10 mins as of this email)
Check the JS and compare the elements it deals with step by step. I assume due to different HTML elements the script doesn't trigger the correct elements.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11746
- Thank you received: 2750
8 years 5 months ago #126366
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?
Tpartners solutions are usually based on the default template I think, so any other template might not work directly out of the box and would need to be adapted.
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: tpartner
The topic has been locked.
- DOwen
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 68
- Thank you received: 0
8 years 5 months ago #126453
by DOwen
Replied by DOwen on topic How to create a question with the option to add another line?
Hey Ben, thanks for this!
However just tried it out but can't seem to get it working; no '+' symbols are showing...
However just tried it out but can't seem to get it working; no '+' symbols are showing...
The topic has been locked.
- DOwen
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 68
- Thank you received: 0
8 years 5 months ago #126455
by DOwen
Just tried to see if I could pick out any issues with the HTML vs the JS, but struggling. Javascript is not my best skill unfortunately!
Replied by DOwen on topic How to create a question with the option to add another line?
Mazi wrote:
Though there are no JavaScript errors the structure of your survey HTML seems to differ so the JavaScript can't access the needed elements.DOwen wrote: The survey should now be public so you can check it out. (May take 10 mins as of this email)
Check the JS and compare the elements it deals with step by step. I assume due to different HTML elements the script doesn't trigger the correct elements.
Just tried to see if I could pick out any issues with the HTML vs the JS, but struggling. Javascript is not my best skill unfortunately!
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3691
8 years 5 months ago #126458
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?
DOwen, the linked survey is not accessible. Can you please attach a sample exported .lss file containing only your array question and the associated JavaScript and an exported zip of your template?
I am just returning from vacation so won't have a lot of free time for the next few days but I'll try to have a quick look.
I am just returning from vacation so won't have a lot of free time for the next few days but I'll try to have a quick look.
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 5 months ago #126459
by DOwen
Replied by DOwen on topic How to create a question with the option to add another line?
Hi tpartner, thanks for this!
I had just temporarily taken down the survey but its back up again now. The questions haven't been edited much, just want to make sure the functionality we need works first.
I appreciate you taking time to take a look, thanks!
I had just temporarily taken down the survey but its back up again now. The questions haven't been edited much, just want to make sure the functionality we need works first.
I appreciate you taking time to take a look, thanks!
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3691
8 years 5 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 5 months ago - 8 years 5 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 5 months ago by DOwen.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3691
8 years 5 months ago - 8 years 5 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 5 months ago by tpartner.
The following user(s) said Thank You: Ben_V, DOwen
The topic has been locked.