The only
one exception is the CompareRule class that is platform specific; it must communicate with the form to
check that the value to validate is equal to the one of another control. This communication happens
using the context field whose value is set at the moment of the instantiation of the rule. The context is
dynamic because it is platform specific and can change if the same system is implemented in a different
environment.
The following code illustrates the implementation of the ValidationRule and of some concrete
subclasses. They are all in the same ValidationRule.hx file but in a real - world application, they
probably can be located in a proper package and each class in its own file.
class ValidationRule
{
public var error(default, null) : String;
public var params(default, null) : Hash < Dynamic > ;
public var context(default, null) : Dynamic;
private function new(context : Dynamic)
{
this.context = context;
params = new Hash();
}
public function validate(value : String)
{
return throw ???AbstractMethod???;
}
private function isValid()
(continued)
409
Chapter 14: More Interactive Content with JavaScript
{
error = ??????;
return true;
}
private function isInvalid(message : String)
{
error = message;
return false;
}
}
class NumericRule extends ValidationRule
{
private function useint()
{
return if(params.
Pages:
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774