Permalink
Browse files

HTML_RANGE is an alias for HTML_NUMBER

  • Loading branch information...
1 parent e03d6c9 commit f7d43ee92f499274785c3d76682766c8b709088b @kentaro committed Nov 4, 2011
@@ -15,18 +15,15 @@ sub rule_of ($) {
$FormValidator::Lite::Rules->{$_[0]};
}
-rule HTML_URL => sub {
- rule_of('HTTP_URL')->();
-};
-
-rule HTML_EMAIL => sub {
- rule_of('EMAIL')->();
-};
+rule HTML_URL => rule_of('HTTP_URL');
+rule HTML_EMAIL => rule_of('EMAIL');
rule HTML_NUMBER => sub {
Scalar::Util::Numeric::isnum($_) ? 1 : 0;
};
+rule HTML_RANGE => rule_of('HTML_NUMBER');
+
rule HTML_MAXLENGTH => sub {
rule_of('LENGTH')->(0, shift);
};
@@ -25,6 +25,8 @@ sub HTML_NUMBER {
Scalar::Util::Numeric::isnum($data) ? SUCCESS : FAIL;
}
+*HTML_RANGE = \&HTML_NUMBER;
+
sub HTML_MAXLENGTH {
my ($self, $params, $args) = @_;
my $data = $params->[0] || '';
@@ -64,11 +64,11 @@ Element
# rules will be extracted as follows:
# [
# text => [ [ HTML_PATTERN => '[A-Za-z0-9]+' ], [ HTML_MAXLENGTH => 255 ] ],
- # url => [ HTML_URL => [ HTML_MAXLENGTH => 255 ], 'HTML_REQUIRED' ],
- # email => [ HTML_EMAIL => [ HTML_MAXLENGTH => 255 ], 'HTML_REQUIRED' ],
+ # url => [ HTML_URL => [ HTML_MAXLENGTH => 255 ], 'NOT_BLANK' ],
+ # email => [ HTML_EMAIL => [ HTML_MAXLENGTH => 255 ], 'NOT_BLANK' ],
# number => [ HTML_NUMBER => [ HTML_MIN => 200 ], [ HTML_MAX => 800 ] ],
- # textarea => [ [ HTML_MAXLENGTH => 1000 ], 'HTML_REQUIRED' ],
- # range => [ [ HTML_MAX => 20 ], [ HTML_MIN => 20 ] ],
+ # textarea => [ [ HTML_MAXLENGTH => 1000 ], 'NOT_BLANK' ],
+ # range => [ HTML_RANGE => [ HTML_MIN => 20 ], [ HTML_MAX => 80 ] ],
# ]
# then do validation using FormValidator::Simple
@@ -85,7 +85,6 @@ sub start {
if (defined $attr->{type} && $TYPE_ATTR_MAP{lc $attr->{type} || ''}) {
my $type = $attr->{type};
- $type = 'number' if (lc $type) eq 'range';
unshift @rules, key($type);
$attrseq = [ grep { lc $_ ne 'type' } @$attrseq ];
}
View
@@ -174,18 +174,18 @@ HTML_MAXLENGTH 45
#parsed
| num
| HTML_MIN 120
-| HTML_NUMBER
+| HTML_RANGE
#html
<input type=range name=num max=120>
#parsed
| num
| HTML_MAX 120
-| HTML_NUMBER
+| HTML_RANGE
#html
<input type=RANGE name=num max=120>
#parsed
| num
| HTML_MAX 120
-| HTML_NUMBER
+| HTML_RANGE

0 comments on commit f7d43ee

Please sign in to comment.