javascript - Enable submit button after validation using parsleyjs -


does parsley have easy way load form submit button disabled , enable validation requirements of form have been met?

i'm not sure mean "easy" after can accomplished.

you need listen events parsley:form:success , parsley:form:error enable / disable button.

you need monitor changes each form field in order force parsley validate. tipically parsley executes validation once click on submit. since submit disabled, you'll need trigger validation manually.

so, here's working example (jsfiddle):

<form>     <input type="text" name="field" data-parsley-required />     <button type="submit" disabled>submit</button> </form>  <script> $(document).ready(function() {     // bind parsley form     $("form").parsley();      // whenever parsley validates successfully, enable submit button     $.listen('parsley:form:success', function(parsleyform) {         parsleyform.$element.find('button').prop('disabled', false);     });      // when validation error occurs, disable submit button     $.listen('parsley:form:error', function(parsleyform) {         parsleyform.$element.find('button').prop('disabled', true);     });      // need monitor form fields , force parsley's validation manually     // result in enabling or disabling submit button     $("form :input").change(function() {         $(this).closest('form').parsley().validate();     }); }); </script> 

note you'll need make monitor changes of fields (inputs, selects, textareas, etc).


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -