Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger parsley validation without submit form?

Given this code, it never works and always returns true whatsoever ?

<form id="my-form" data-validate="parsley">   <p>     <label for="username">Username * :</label>     <input type="text" id="username" name="username" data-required="true" >   </p>    <p>     <label for="email">Email Address * :</label>     <input type="text" id="email" name="email" data-required="true" >   </p>    <br/>    <!-- Validate all the form fields by clicking this button -->   <a class="btn btn-danger" id="validate" >Validate All</a> </form>  <script> var $form = $('#my-form'); $('#validate').click (function () {     if ( $form.parsley('validate') )       console.log ( 'valid' ); <-- always goes here     else       console.log ('invalid'); });  </script> 

So my question is if there is a way to trigger parsley validation without adding a submit button ?

like image 946
Hoan Dang Avatar asked Apr 01 '14 09:04

Hoan Dang


People also ask

What is data parsley trigger?

data-parsley-trigger="input" Specify one or many javascript events that will trigger item validation, before any failure. To set multiple events, separate them with a space data-parsley-trigger="focusin focusout" . Default is null . See the various events supported by jQuery.

What is parsley validation?

Parsley is a javascript form validation library. It helps you provide your users feedback on their form submission before sending it to your server. It saves you bandwidth, server load and it saves time for your user.

How do you remove parsley validation?

You can deactivate parsley validation, remove the required attribute for the element that you want to disable validation for, and then reactivate Parsley. First, let's assume you bound Parsley validation to your form like so: $('#my-form'). parsley({ //options });


1 Answers

$form.parsley('validate') is 1.x API. It was deprecated in 2.x versions you might use.

Try $form.parsley().validate() instead.

Best

like image 78
guillaumepotier Avatar answered Sep 20 '22 15:09

guillaumepotier