guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.05k stars 1.32k forks source link

Listening for any error messages #1362

Open toplisek opened 2 years ago

toplisek commented 2 years ago

I try to listen for an error in the second field. I have an issue it will not be added a class to the button. Is it technically possible to do this? A button is pushed on the second element under an error but an error is under input cell. So, I try to add a new class to the button when an error arise for the second element. I have used if (input.dataset.parsleyId === '13') ` $(document).ready(function() { var parsleyConfig = { errorsContainer: function(parsleyField) { return $('#errors'); } };

$("form").parsley(parsleyConfig); if (input.dataset.parsleyId === '13') { button.setAttribute("class", "fixed-margin-button1"); }

$("form").on('submit', function(e) { var f = $(this); f.parsley().validate();

if (f.parsley().isValid()) {
 alert('The form is valid');
} else {
 alert('There are validation errors');
}

e.preventDefault();

} ); } ); `