Welcome to the LimeSurvey Community Forum

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

Upload modal - Strange behavior after upgrade to version 5

  • squidy
  • squidy's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 months 4 weeks ago #251619 by squidy
Hi again, Tony..

I am facing a problem with this script.

When the participant uploads a file to the modal and clicks save page to finish later, the file disappears. But this only happens if the participant clicks save on the same modal page.

Do you know what happens?

Using LS 5.x

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 months 3 weeks ago #251662 by tpartner
Try this:

Code:
<script type="text/javascript" data-author="Tony Partner">  
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify the questions
    var qArrayID = '{QID}';
    var qArray = $('#question'+qArrayID);
    var arrayLength = $('tr[id^="javatbd"]', qArray).length;
    var qUploads = qArray.nextAll('.upload-files:lt('+arrayLength+')');
 
    // Add some classes
    qArray.addClass('array-with-uploads-question');
    $(qUploads).addClass('hidden');
 
    // Insert the "Upload" buttons
    $('tr[id^="javatbd"] .answer-item:last-child', qArray).each(function(i) {
      $('*', this).remove();
      $(this).append('<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#upload-'+qArrayID+'-'+(i+1)+'" data-backdrop="static" data-keyboard="false">Anexar comprovante</button>');
    });
 
    // Loop through the upload questions
    $(qUploads).each(function(i) {
      // Create a modal
      $('body').append('<div class="modal upload-modal" id="upload-'+qArrayID+'-'+(i+1)+'" tabindex="-1" role="dialog">\
                <div class="modal-dialog" role="document">\
                  <div class="modal-content">\
                    <div class="modal-header">\
                      <h5 class="modal-title">'+$('.ls-label-question', this).html()+'</h5>\
                    </div>\
                    <div class="modal-body">\
                    </div>\
                    <div class="modal-footer">\
                      <button type="button" class="btn btn-primary" data-bs-dismiss="modal">OK</button>\
                    </div>\
                  </div>\
                </div>\
              </div>');
 
      // Move this question into the modal
      $('#upload-'+qArrayID+'-'+(i+1)+' .modal-body').append($(this));
      $(this).removeClass('hidden');
    });
 
    // Interrupt the Next/Submit function (to put upload questions back in the form)
    $('#limesurvey').on('submit', function(e) {    
      $('.upload-modal .upload-files').appendTo($('.group-container:eq(0)')).addClass('hidden');
    });    
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • squidy
  • squidy's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 months 3 weeks ago #251675 by squidy
Brilliant... Thank you again...

Using LS 5.x

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose