Re Validation form (Metronic 8.2- html)
Hello,
How can the form validation function be called again in Metronic 8.2? Because when an item in the form is removed or added by hide() and show(), the validation on these items does not work correctly.
When an item is hidden, the class "fv-row" is removed from the div.
When an item is show, the class "fv-row" is added to div.
Despite what I have mentioned, the form validation still does not work correctly on the new changes and seems to require being called again.
I would appreciate your guidance. Thank you!
Replies (1)
Deleted comment
Deleted comment
Hi,
Please try to refer to the official docs of the plugin https://formvalidation.io/ and refer to the below code:
<pre> // Assume `form` is the form element, and `validator` is the FormValidation instance const form = document.querySelector('#yourFormId'); const validator = FormValidation.formValidation(form, { fields: { // Define your fields and their validation rules fieldName: { validators: { notEmpty: { message: 'This field is required', }, }, }, }, plugins: { trigger: new FormValidation.plugins.Trigger(), bootstrap: new FormValidation.plugins.Bootstrap(), }, }); // When an element is shown function onElementShown() { // Update FormValidation to revalidate the shown element validator.addField('fieldName', { validators: { notEmpty: { message: 'This field is required', }, }, }); } // When an element is hidden function onElementHidden() { // Update FormValidation to ignore the hidden element validator.disableValidator('fieldName'); } </pre>Regards, Sean