Subject: | new HTML5 input type support |
Hi. "Changes" file says new html5 input types are supported in
HTML::FillInForm 2.1, but apparently the feature is missing. Here's a
patch to fix and a test to confirm. Thanks.
Subject: | fillinform_html5.patch |
diff --git a/lib/HTML/FillInForm.pm b/lib/HTML/FillInForm.pm
index 07a6d94..22c4aa4 100644
--- a/lib/HTML/FillInForm.pm
+++ b/lib/HTML/FillInForm.pm
@@ -273,7 +273,7 @@ sub start {
if (defined($value)){
# check for input type, noting that default type is text
if (!exists $attr->{'type'} ||
- $attr->{'type'} =~ /^(text|textfield|hidden|)$/i){
+ $attr->{'type'} =~ /^(text|textfield|hidden|tel|search|url|email|datetime|date|month|week|time|datetime\-local|number|range|color|)$/i){
if ( ref($value) eq 'ARRAY' ) {
$value = shift @$value;
$value = '' unless defined $value;
diff --git a/t/27_html5.t b/t/27_html5.t
new file mode 100644
index 0000000..3ac999b
--- /dev/null
+++ b/t/27_html5.t
@@ -0,0 +1,35 @@
+use strict;
+use warnings FATAL => 'all';
+use Test::More;
+use HTML::FillInForm;
+
+my %data = (
+ tel => '00-0000-0000',
+ search => 'search word',
+ url => 'http://localhost',
+ email => 'foo@example.com',
+ datetime => '2012-10-10T00:00Z',
+ date => '2012-10-10',
+ month => '2012-10',
+ week => '2012-W10',
+ time => '00:00',
+ 'datetime-local' => '2012-10-10T00:00',
+ number => 1,
+ range => 10,
+ color => '#000000',
+);
+
+plan tests => scalar keys %data;
+
+my $html =
+ '<!doctype html><html><body><form>' .
+ (join '', map { qq/<input type="$_" name="$_">/ } keys %data) .
+ '</form></body></html>';
+
+
+my $result = HTML::FillInForm->new->fill(\$html, \%data);
+
+for my $key (keys %data) {
+ my ($input) = $result =~ /(<input[^>]+type="$key"[^>]*>)/;
+ like $input => qr/value="$data{$key}"/, "filled $key";
+}