Prev | Current Page 766 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

When this happens, the validation check is executed but only on the control that has
(continued)
411
Chapter 14: More Interactive Content with JavaScript
lost the focus and an error is reported eventually. In this way, the user does not have to wait until the
final submission to be informed if he has made some mistakes. The class is also responsible for managing
(displaying and removing) error messages.
import js.Dom;
class FormValidator
{
private static var rules : Hash < { rclass:Class < ValidationRule > ,
params : Dynamic } > = new Hash();
private var fields : Hash < { el : FormElement, rules : Array < ValidationRule > } > ;
public function new(form : Form)
{
form.onsubmit = submit;
form.onreset = reset;
var inputs = form.getElementsByTagName(???input???);
fields = new Hash();
var self = this;
for(i in 0...inputs.length)
{
var crules = new Array();
var validation = inputs[i].getAttribute(???validation???);
if(validation != null)
{
for(r in parseRules(validation))
{
if(!rules.exists(r.


Pages:
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778