https://github.com/saintedlama/interceptable-validators
This small javascript library adds the possibility to intercept validation in ASP.NET
https://github.com/saintedlama/interceptable-validators
Last synced: 19 days ago
JSON representation
This small javascript library adds the possibility to intercept validation in ASP.NET
- Host: GitHub
- URL: https://github.com/saintedlama/interceptable-validators
- Owner: saintedlama
- Created: 2012-07-11T13:17:55.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2012-12-20T10:05:57.000Z (almost 13 years ago)
- Last Synced: 2025-02-28T12:43:11.457Z (9 months ago)
- Language: ASP
- Size: 270 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Interceptable Validators
ASP.NET Validators are a quite well designed but rather inflexible approach to form validation. This project provides a small javascript file to intercept ASP.NET validation with your own javascript code.
Validators can be intercepted on a page level or field level.
# HowTo
Add a the script `interceptableValidators.js` to your site and initialize validators **AFTER** the ASP.NET validation code block. This can be done by using jQuery's DomReady event
$(function () {
interceptPageValidation({
beforeValidation: function () {
console.log('beforeValidatorOnSubmit');
},
afterValidation: function (valid) {
console.log('afterValidatorOnSubmit' + valid);
}
});
interceptFieldValidation({
beforeValidation: function (val) {
console.log('beforeFieldValidation' + val);
},
afterValidation: function (val, valid) {
var inputFields = $(val).parent('.input-fields:first');
if (valid) {
inputFields.removeClass('error');
} else {
inputFields.addClass('error');
}
}
});
});
To intercept page validation use the function `interceptPageValidation`, to intercept field validation use the function `interceptFieldValidation`.
Both functions expect an object passed as parameter that can defines methods
* beforeValidation
* afterValidation
For interceptFieldValidation you get parameters val (DOM element beeing validated) and valid (only in afterValidation) passed to your functions. For page validation your functions get valid passed (only in afterValidation).
# Demo
Just open InterceptableValidators.sln in Visual Studio 2010+ to see how interception works.
# Dependencies
This plugin does not depend on jQuery or any other javascript framework.