Permalink
Browse files

add 'preserve_case' attribute to Email field

  • Loading branch information...
1 parent 0d9a5a6 commit b8e9b2d9250ea25655055527e9442cf7bd9165b2 @gshank committed Sep 26, 2013
Showing with 23 additions and 3 deletions.
  1. +1 −0 Changes
  2. +14 −1 lib/HTML/FormHandler/Field/Email.pm
  3. +8 −2 t/fields/fields.t
View
@@ -16,6 +16,7 @@
'has-warning' instead of the former 'error' class. 'control-group' was
changed to 'form-group'. The 'form-control' class has been added to
text, passowrd, textarea, and select fields.
+ Add 'preserve_case' attribute to Email field
0.40028 Sat Sep 21, 2013
Fixed bug when rendering blocks with 'run' (results)
@@ -16,6 +16,11 @@ has 'email_valid_params' => (
isa => 'HashRef',
);
+has 'preserve_case' => (
+ is => 'rw',
+ isa => 'Bool',
+);
+
sub get_class_messages {
my $self = shift;
return {
@@ -27,7 +32,12 @@ sub get_class_messages {
apply(
[
{
- transform => sub { lc( $_[0] ) }
+ transform => sub {
+ my ( $value, $field ) = @_;
+ return $value
+ if $field->preserve_case;
+ return lc( $value );
+ }
},
{
check => sub {
@@ -59,6 +69,9 @@ This field has an 'email_valid_params' attribute that accepts a hash
reference of extra values passed to L<Email::Valid/address> when
validating email addresses.
+If you want to preserve the case of the email address, set the
+'preserve_case' attribute.
+
=head1 DEPENDENCIES
L<Email::Valid>
View
@@ -72,13 +72,19 @@ ok( defined $field, 'new() called' );
my $address = 'test@example.com';
$field->_set_input( $address );
$field->validate_field;
-ok( !$field->has_errors, 'Test for errors 1' );
+ok( !$field->has_errors, 'Email Test for errors 1' );
is( $field->value, $address, 'is value input string' );
my $Address = 'Test@example.com';
$field->_set_input( $Address );
$field->validate_field;
-ok( !$field->has_errors, 'Test for errors 2' );
+ok( !$field->has_errors, 'Email Test for errors 2' );
is( $field->value, lc($Address), 'is value input string' );
+$field->preserve_case(1);
+$field->_set_input( $Address );
+$field->validate_field;
+ok( !$field->has_errors, 'Email Test for errors 3' );
+is( $field->value, $Address, 'field was not lowercased' );
+
$field->_set_input( 'test @ example . com' );
$field->validate_field;

0 comments on commit b8e9b2d

Please sign in to comment.