victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
973 stars 478 forks source link

Custom Sanitizer #634

Open trusteddigital opened 6 years ago

trusteddigital commented 6 years ago

You've got the ability to create custom validators which is excellent but I'm wondering how you would approach writing a custom sanitiser? We've got a solution we currently apply which is to run our sanitation before we then call the validator programmatically however if we were able to build it into the same workflow, that'd be useful.

trusteddigital commented 6 years ago

I've actually just thought of a solution (and tested) which is to write a custom validator which just runs my sanitation then returns 0. But would still be interested if there's a better way

victorjonsson commented 6 years ago

That probably works. But I guess you would want the sanitation to take place first of all. This is achieved by putting your custom validator first in the data-validation declaration but I dislike the solution anyway because of the following reasons:

I guess that you could let the sanitize module provide a way to implement custom sanitizers. Something looking like:

$.formUtils.addSanitizer({
   name: 'customSanitation',
   sanitationFunction: ($element, value, config) => {
     return '';
   }
});
trusteddigital commented 6 years ago

Yes exactly. I agree that extending the sanitize functionality in this way would be best. The work around works fine for this project but if I get a chance I'll have a go at writing this.

victorjonsson commented 6 years ago

:+1:

trusteddigital commented 6 years ago

See #643

elmatou commented 6 years ago

:+1: