Welcome to the LimeSurvey Community Forum

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

Show array answers one by one

  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 months ago - 3 years 2 months ago #222761 by MikhailGorbunov
Show array answers one by one was created by MikhailGorbunov
Hello.
I need to show answers in Array question hiding answered and shown one first unanswered.
Main idea is follow. Respondent waching video and set like if hi likes and dislike if not.
We save respondent ID and timestamp of video when answer is klicked.
So i need this array question: 
Like1 Like Dislike
Like2 Like Dislike
Like3 Like Dislike
Like4 Like Dislike
Like5 Like Dislike
shows only one row, hide answered when like/dislike clicked and shows next empty row.
Is it posible?
Last edit: 3 years 2 months ago by MikhailGorbunov.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #222766 by tpartner
Replied by tpartner on topic Show array answers one by one
What behaviour are you looking for when all rows are answered?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 months ago #222768 by MikhailGorbunov
Replied by MikhailGorbunov on topic Show array answers one by one
I`ll do so many rows, they can`t finish. 500 mayby or 1000.... So rows can`t be all answered. Respondent just press finish when video stops.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #222769 by holch
Replied by holch on topic Show array answers one by one

I`ll do so many rows, they can`t finish. 500 mayby or 1000....

Remember that each row means a column in the database and depending on your database engine, you might run into a limit at around 1000 columns...

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #222770 by holch
Replied by holch on topic Show array answers one by one
Wouldn't it make more sense to create a hidden (via CSS) text question, put two buttons into the interface and record the clicks on the buttons with timestamp via Javascript into this text question?

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 months ago #222774 by MikhailGorbunov
Replied by MikhailGorbunov on topic Show array answers one by one
Sure, do.
But i did array after i found script in forums.limesurvey.org/forum/design-issue...o-add-new-answer-row
to hide/shown rows in array.
I did not find javascript to create hidden text and put two buttons to save smth into.
But why not?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #222776 by tpartner
Replied by tpartner on topic Show array answers one by one
This script in the question source of an LS 3.x array question will show rows sequentially as they are answered.
 
 
Code:
Q1...
<script type="text/javascript" data-author="Tony Partner">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
    var thisTable = $('table.subquestion-list:eq(0)', thisQuestion);
 
    // Hide all but the first array rows
    $('tbody tr:not(:first)', thisQuestion).hide();
 
    // Remove repeat heading rows
    if($('tbody', thisTable).length > 0) {
      $('tbody:gt(0) tr[id^="javatbd"]', thisTable).appendTo($('tbody:eq(0)', thisTable));
      $('tbody:gt(0)', thisTable).remove();
    }
 
    // Listener on the radios
    $('.answer-item :radio', thisQuestion).on('click', function(event) { 
      var thisRow = $(this).closest($('tr[id^="javatbd"]'));
      var nextRow = thisRow.nextAll('tr[id^="javatbd"]:eq(0)');
      if(nextRow.length > 0) {
         thisRow.fadeOut(300, function(e) {
           nextRow.fadeIn(300);
         });
      }
    });
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...4594.lss
File Size:20 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 months ago #222778 by MikhailGorbunov
Replied by MikhailGorbunov on topic Show array answers one by one
Wow! Works fine! Many thanks!!!
The topic has been locked.
  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 1 month ago - 3 years 1 month ago #222798 by MikhailGorbunov
Replied by MikhailGorbunov on topic Show array answers one by one
Dear tpartner.

Can you please explain usage of
", thisQuestion" in this selector?
Code:
$('.answer-item :radio', thisQuestion)


I`m unable to find any documentation about commas in selector except this $(‘img[alt],img[title]’) meaning alt OR title.
But why should i select items with (type=radio IN class=answer-item) OR (question5 (thisQuestion))?
Is this not a jquery syntax?
Please explain.
Last edit: 3 years 1 month ago by MikhailGorbunov. Reason: Wrong text format
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #222813 by tpartner
Replied by tpartner on topic Show array answers one by one
This IS jQuery syntax.

Selector context (or scope) - api.jquery.com/jquery/

The selector will return all '.answer-item :radio' elements within thisQuestion which is previously defined.

You need to put a listener on only the radio inputs in the question where the JavaScript resides, not on all radio inputs in the page (there may be more questions).

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 1 month ago #222816 by MikhailGorbunov
Replied by MikhailGorbunov on topic Show array answers one by one
Thank you tpartner)
The topic has been locked.
  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 4 days ago - 3 years 4 days ago #224477 by MikhailGorbunov
Replied by MikhailGorbunov on topic Show array answers one by one
Dear Tony Partner,
I`m add some event on keypress at this script:

Add some ajax request after nextRow fade in, to save video timing in separate SQL table, like this
Code:
$.ajax({ url: check_quota_url, . . .

and add a keypress event to make this event happen by + or - key pressed.
Code:
$(document).keypress(function (e)
{
var key = e.which;
if(key == 61 || key == 43 ) // the enter key code
{
$('#answer645263X5X10146Val1-Like').click();
return false;
}
if(key == 95 || key == 45) // the enter key code
{
$('#answer645263X5X10146Val1-Dis').click();
return false;
}
}
);

So, ajax request is done fine, each time when + or - key pressed, but
Code:
thisRow.fadeOut(300, function(e) { nextRow.fadeIn(300); });

works only once. I know i should do something with
Code:
Val1-Like
, and
Code:
Val1-Dis
in radio ids, but i can`t figure out correct solution. Can you please help with this?
Last edit: 3 years 4 days ago by MikhailGorbunov.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose