The simplest solution is to exclude all hidden inputs, for example:
$('#' + formID).parsley({ excluded: "input[type=button], input[type=submit], input[type=reset], input[type=hidden], input:hidden" });
Thus, the check will only link visible inputs. However, this forces you to destroy and apply Parsley every time the entrance changes visibility.
To avoid this, you can use the following "not very elegant" solution. This code would be better in the "parsley: field: validate" event, but I couldn't get it to work.
Using the "parsley: validated" field, the check has already been completed, and now we will change the check result to true and hide the error container.
$('#' + formID).parsley(); $.listen('parsley:field:validated', function(fieldInstance){ if (fieldInstance.$element.is(":hidden")) { // hide the message wrapper fieldInstance._ui.$errorsWrapper.css('display', 'none'); // set validation result to true fieldInstance.validationResult = true; return true; } });
As in Parsley 2.1. * parsley:field:validated event throws the following message
The pubsub parsley module is deprecated; use the appropriate jQuery event method instead
Instead of parsley:field:validated you should use the field:validated event
In recent versions, $.listen() deprecated. You should use Parsley.on() . Example:
Parsley.on('field:validated', function(fieldInstance){ if (fieldInstance.$element.is(":hidden")) { // hide the message wrapper fieldInstance._ui.$errorsWrapper.css('display', 'none'); // set validation result to true fieldInstance.validationResult = true; return true; } });
Luís Cruz
source share