Note: see http://codefromnathan.blogspot.be/2012/10/since-ive-been-little-bored-i-decided.html for the basics of this script.
1. Show errors in all browsers
From now on this script shows all errors it finds in all browsers. If you don't like this behavior, you can change it so that it only shows the errors for the input types (and attributes) that the current browser doesn't support by setting the option 'IgnoreBrowserSupport' to false. For example:$(".SubmitButton").webforms({
"IgnoreBrowserSupport": "false"
})
2. Added 'pattern' support
From this point on the script supports the 'pattern' attribute. This means that this script can read the value of the pattern attribute and then run in against the value of the textbox.For more information about the pattern attribute itself see:
- http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#the-pattern-attribute
- http://www.w3schools.com/html5/att_input_pattern.asp
3. Support for a callback Function
If you have some JavaScript code that you want to run as soon as this script has done checking the input elements for errors. Then you can use the 'CallBackFunction' option. This option takes a function as a value. Here is a basic example:function demoformInOrde(submitButton, container){
alert("All the fields in the container '" + container + "' are filled in correctly!");
return false;
}
$(document).ready(function(){
$(".mySubmitButton").webforms({
"CallBackFunction": demoformInOrde
})
});
The name of the function 'demoformInOrde' can (obviously) be changed to anything you like. If you return false, the form will not be submitted. If you return any other value (or no value at all) then the form will be submitted. The function will only get called when there are no errors detected and it will automatically get 2 parameters send to it.
- The first parameter is an object containing the submit button itself.
- The 2nd parameter is a string containing the 'container' option that was passed to the script.
Download
If you want to take a look at the code yourself (or give it a try), then you can download it from:https://sites.google.com/site/codefromnathan/Webforms.zip.
Please note that it isn't finished and that it still contains bugs.
License: MIT
version: 0.0.2
Known issues:
- Not all input types are supported (yet).
- In browsers that don't support the 'color' input, the script still expects the user to manually input the hex. value of the color.
- There should be an option to show the error messages next to their input type.
- Code should get optimized in some places
No comments:
Post a Comment