Welcome to the LimeSurvey Community Forum

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

Prevent question from reloading

  • hamstr
  • hamstr's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 6 months ago #188987 by hamstr
Prevent question from reloading was created by hamstr
Dear LimeSurvey community!

I am facing a quite complicated issue and I hope someone might be able to help me out...

Participants are asked to rate short musical excerpts. The question group is designed in a way that first only a text display question is shown with the audio being played one time while all other questions (comprising the rating) as well as the next button are hidden. When the audio has ended, the hidden questions appear and the audio is triggered to be played a second time. Now as all questions are mandatory, the whole page is refreshed if participants forget to answer a question. Then this whole process starts all over, including the rating questions and the next button to be hidden.

Is there any way to stop the page from refreshing in case a question has not been answered but only show the warning message that there are unanswered items left? I'm using LS 2.64.1.

Any kind of advice is highly appreciated!

Best,
hamstr
The topic has been locked.
More
4 years 6 months ago #189069 by Bigred01
Replied by Bigred01 on topic Prevent question from reloading
You can add some JS to validate your questions and prevent the form submit if anything is invalid. I am not aware of anything in lime that would allow for this out of the box.

How are you initially triggering your questions to show when the audio is done? I imagine you are already using some JS to accomplish this. I usually store the progress of a media file in a hidden input so i can reference it again on page load. So when a media file has fully finished playing, store something like 'done' in a hidden field. Then when the page loads and I see done, there is no need to force them to view/listen to the media again, they can just start answering where they left off. This also allows you to make use of the limesurvey expressions for skip logic. Be sure to run checkconditions() on your inputs though when setting values like this.
The following user(s) said Thank You: hamstr
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 6 months ago #189076 by DenisChenu
Replied by DenisChenu on topic Prevent question from reloading
Not 2.64.1, butr Skelvanilla can disable move next using HTML5 input attributes. Th aria-live javascript

For mandatory part :
Code:
$("[id^='question'].mandatory").each(function() {
            $(this).find('.text-item:not(.other-text-item):not(.slider-item):not(.comment-item) input:text,.text-item:not(.other-text-item):not(.comment-item) textarea,.dropdown-item select,.radio-item input:radio').attr('required',true);
        });
can work in 2.64 too.

But +1 for @Bigred01 : you already have a JS for media, then adding a question to track media is done or not can be the best solution.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • hamstr
  • hamstr's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 6 months ago - 4 years 6 months ago #189404 by hamstr
Replied by hamstr on topic Prevent question from reloading

Bigred01 wrote: I usually store the progress of a media file in a hidden input so i can reference it again on page load. So when a media file has fully finished playing, store something like 'done' in a hidden field. Then when the page loads and I see done, there is no need to force them to view/listen to the media again, they can just start answering where they left off.


Thanks so much for this input, Bigred01!

It actually did not occur to me to store a value in a hidden field. I've now set up a hidden short-text question where "done" is stored after the first musical excerpt has ended. The ratings remain hidden as long as the short-text is empty. It was essential to trigger the value via java script (as described here: www.limesurvey.org/forum/can-i-do-this-w...nswer-via-javascript ) which resulted in the following code that now works perfectly fine for me:

Code:
<script type="text/javascript" charset="utf-8">
       $(document).ready(function(){
     document.getElementById("myAudio").addEventListener('ended',myHandler,false);
         function myHandler(e) {
             if(!e) { e = window.event; }
        $('#answer{SGQ}').val('done');
        $("#answer{SGQ}").trigger('keyup');
         }    });    
</script>
Last edit: 4 years 6 months ago by hamstr.
The topic has been locked.
More
4 years 6 months ago #189405 by Bigred01
Replied by Bigred01 on topic Prevent question from reloading
Nice.

I have resorted to using the limesurvey checkconditions() function directly for triggering expression manager logic rather than firing an arbitrary event on an input. Sooner or later you end up fighting other event listeners, propagation etc ... and it just becomes dirty and annoying. I recommend checking that function out from the survey_runtime.js file.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose