jQuery-Form-Validator icon indicating copy to clipboard operation
jQuery-Form-Validator copied to clipboard

Question: How to use programmatic validation without submit

Open jzrider opened this issue 7 years ago • 0 comments
trafficstars

Having some difficulty getting the $.fn.isValid to work...

(update) I did get this to work.

Your example showed $(this).isValid() being called. I had to change "this" to my form id.

thanks!

<script lang="javascript">
     $(document).ready(function() {  // same as document ready
         var errors = [];
         var lang = {};
         var conf = {
           		 form : '#order_shipment_CRUD_save',
        			    // reference to elements and the validation rules that should be applied
      			    validate : {
      			      'carrier' : {
      			      validation : 'required'
      			      }
      			    },
                onElementValidate : function(valid, $el, $form, errorMess) {
                 console.log("calling onElementValidate");
                   if( !valid ) {
                     // gather up the failed validations
                     console.log("pushing an error ");
                     errors.push({el: $el, error: errorMess});
                   }
                 }
               };
       $('#order_shipment_CRUD_save_${index}').on('click', function(){
         $('#trackingNumbers option').prop('selected', true);
         console.log("CLICKED IT")
            // reset error array
         errors = [];
         console.log(this);
         if( !$.fn.isValid(lang, conf, false) ) {
           displayErrors( errors );
         } 
       });
     });
   </script>

jzrider avatar Sep 04 '18 19:09 jzrider