Closed jaanush closed 10 years ago
This would be a great addition since there seems to be a general lack of jQuery validation solutions that do not rely on submitting the form - something you don't want in a lot of ajax solutions
but, this jQuery validation works indeed with the OnBlur event...the user knows all the invalid inputs when the control lost focus!!! you don't need submit anything. I use it with my xajax project and combined with a good CSS works like a charm. this is a basic example: looks like this:
As you can saw, the example don't have any submit button. I deleted
Have I understood this correctly that you want $(...).isValid()
to do a silent validation of the form and return a boolean whether the form is valid (without triggering any error messages)?
Like Carlos points out you don't need to have a submit button.
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.1.27/jquery.form-validator.min.js"></script>
</head>
<body>
<form action="#" id="the-form">
<input type="text" name="user" data-validation="required" />
</form>
<script>
// setup validation on form
$.validate();
// Ajax action when form is submitted
var $form = $('#the-form').on('submit', function() {
// ajax stuff...
return false;
});
// programmatically submitting the form
$form.get(0).submit(); // or $form.trigger('submit')
</script>
</body>
</html>
Can't you use $.validateForm(language, config) for this?
Yes, but then you must create the language and config variable yourself.
Use the triggerHandler to trigger a submit without actually submitting the form.
$('#some-button-id').on('click', function(evt){
evt.preventDefault();
$(this).closest('form').triggerHandler('submit');
});
Then you can call your after validation function in the onSuccess callback.
$.validate({
form : '#someFormId',
onSuccess : function(){
//Do Work Here
}
});
I'm closing this for now...
great ! thank you
It would be nice if there was some way to trigger validation without submitting the form, like $('#myform').isValid()