Plugin Directory

Changeset 2673436


Ignore:
Timestamp:
02/05/2022 04:43:41 PM (4 years ago)
Author:
morphii
Message:

Added Intensity Validation On Submit button

File:
1 edited

Legend:

Unmodified
Added
Removed
  • morphii/trunk/assets/js/morphii-custom.js

    r2673321 r2673436  
    33  jQuery.noConflict();
    44  var collection = null;
    5 
     5  var intensitySet=false;
    66  window.onload = function() {
    77    createWidget();
     
    5656      },
    5757      slider: {
    58         initial_intensity: 0.2,
     58        initial_intensity: 0.0,
    5959        show_animation: true,
    6060        anchor_labels: {
     
    161161  function selectionChangeCallback(event) {
    162162    //console.log('Selection Change callback: ' + JSON.stringify(event, null, 2));
     163    var submitButton = document.getElementById('morphii-submit-button');
     164    if (submitButton) {
     165   
     166      if (event.selection_required_valid === true) {
     167
     168        submitButton.removeAttribute('disabled');
     169      }
     170      else {
     171         
     172
     173        submitButton.setAttribute('disabled', 'disabled');
     174      }
     175    }
    163176    var noUiOrigin=document.getElementsByClassName('noUi-origin')[0];
    164177    var observer = new MutationObserver(function(mutations) {
    165178    var style=jQuery(".noUi-origin").attr("style");
     179    intensitySet=true;
    166180   // console.log(style);
    167   var submitButton = document.getElementById('morphii-submit-button');
    168     if (submitButton) {
    169    
    170       if (event.selection_required_valid === true) {
    171       jQuery(".morphii-questions").find(".intensity-error").remove();
    172         submitButton.removeAttribute('disabled');
    173       }
    174       else {
    175           if(jQuery(".morphii-questions").find(".intensity-error").length==0)
    176           jQuery(".morphii-questions").append("<span class='intensity-error'><br/><hr/><p style='color:red'>Oops! You forgot to tell us how intense your feelings are. Use the slider to adjust the facial expression to show us</p></span>");
    177 
    178         submitButton.setAttribute('disabled', 'disabled');
    179       }
    180     }
     181 
    181182});
    182183
     
    191192
    192193  function submit(event) {
     194      if(intensitySet && jQuery(".noUi-origin").attr("style")!="left: 0%;"){
     195          console.log("Intensity Set");
     196       jQuery(".morphii-questions").find(".intensity-error").remove();
     197   
     198      }
     199      else{
     200          if(jQuery(".morphii-questions").find(".intensity-error").length==0)
     201      {
     202          jQuery(".morphii-questions").append("<span class='intensity-error'><br/><hr/><p style='color:red'>Oops! You forgot to tell us how intense your feelings are. Use the slider to adjust the facial expression to show us</p></span>");   
     203          return false;
     204      }
     205      }
     206     
    193207    if (collection) {
    194208      var submitButton = document.getElementById('morphii-submit-button');
Note: See TracChangeset for help on using the changeset viewer.