Question

I'm simply trying to add a custom validator to the Parsley config. The default validators are working but my custom one won't fire. Fiddle

The script (simplified)

$('#form').parsley({
validators: {
  custom: function () {
    return {
      validate: function (eleVal, attrVal) {
        return false;
      },            
    };
  }
},
messages: {
    custom: "Custom validator message"
}
});

The HTML (simplified)

<form id="form">
  <input type="text" data-parsley-trigger="keyup" data-parsley-custom="true" required />
  <input type="submit">
</form>

I followed these docs. Note that by removing the the required attribute, you have to add data-parsley-validate-if-empty. I just put required in to demonstrate that the default validators work.

Has anyone else run into this or did I miss something?

Était-ce utile?

La solution

You are right for data-parsley-validate-if-empty if you remove required validator, along with your custom one.

But look at this extra validator defined here: https://github.com/guillaumepotier/Parsley.js/blob/master/src/extra/validator/dateiso.js

or this doc here: http://parsleyjs.org/doc/index.html#psly-validators-craft

You have the wrong syntax for your validator, the validation function must be in a fn key and a priority defined. That way it should work.

Best

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top