victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
972 stars 476 forks source link

Question: How to use programmatic validation without submit #717

Open jzrider opened 6 years ago

jzrider commented 6 years ago

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>