Reputation: 41
I want to display a parsley message in an else clause of my javascript code:
if ( ...is valid ) {
//do things
} else {
//display parsley error
}
I know that Parsley allows custom validators as documented here: http://parsleyjs.org/documentation.html#javascript
But I merely want to display the message until the field is modified. I could create a validator such as:
$( '#myInput' ).parsley( {
validators: {
alwaysFalse: function ( val ) {
return false;
}
}
, messages: {
myMessage: "Form is invalid"
}
});
But then how would I trigger this and only this validator? (There is another validator already attached)
Upvotes: 2
Views: 2154
Reputation: 96
your messages object should be a mirror of your validators object but with the messages to display.
messages: {
alwaysFalse: "Form is invalid"
}
and you could try
validators: {
alwaysFalse: function(val){
return false;
},
required: function ( val ) {
return false;
}
}
also
Warning : you must remove parsley-validate auto-binding code in your forms DOM to allow you to override the default processing and use Parsley purely from javascript.
it seems like what you really want this: http://parsleyjs.org/documentation.html#parsleyfield check out parsley-error-container
the trigger should be $( '#myInput' ).parsley( 'validate' );
or not 100% sure on this but you should be able to call each one like this:
$( '#myInput' ).parsley('alwaysFalse');
and if they need inputs or data:
$( '#myInput' ).parsley('alwaysFalse','inputs','data');
Upvotes: 1