Browse files

Float field => tweak messages, add tests

  • Loading branch information...
1 parent 68b6260 commit 8cefb756dada703a1412f3ad71957403cc8c341d @gshank committed Jan 21, 2012
Showing with 39 additions and 9 deletions.
  1. +8 −2 lib/HTML/FormHandler/Field/Float.pm
  2. +2 −2 lib/HTML/FormHandler/I18N/tr_tr.pm
  3. +22 −0 t/fields.t
  4. +7 −5 util/messages
View
10 lib/HTML/FormHandler/Field/Float.pm
@@ -13,8 +13,8 @@ has 'decimal_symbol_for_db' => ( isa => 'Str', is => 'rw', default => '.');
our $class_messages = {
'float_needed' => 'Must be a number. May contain numbers, +, - and decimal separator \'[_1]\'',
- 'float_size' => 'May have maximum size of [_1], but has [_2]',
- 'float_precision' => 'May have maximum [_1] [quant,_1,number] after the decimal point, but has [_2]',
+ 'float_size' => 'Total size of number must be less than or equal to [_1], but is [_2]',
+ 'float_precision' => 'May have a maximum of [quant,_1,digit] after the decimal point, but has [_2]',
};
sub get_class_messages {
@@ -112,4 +112,10 @@ Widget type is 'text'.
range_end => 100
);
+=head2 messages
+
+ float_needed
+ float_size
+ float_precision
+
=cut
View
4 lib/HTML/FormHandler/I18N/tr_tr.pm
@@ -60,8 +60,8 @@ our %Lexicon = (
# H::F::Field::FloatNumber
'Must be a number. May contain numbers, +, - and decimal separator \'[_1]\'', => 'Bir sayı olmalı. Rakamlar, +, -, ve ondalık ayırıcı \'[_1]\' içerebilir',
- 'May have maximum size of [_1], but has [_2]', => 'Maksimum [_1] rakam içerebilir ama [_2] rakam içeriyor',
- 'May have maximum [_1] [quant,_1,number] after decimal point, but has [_2]', => 'Ayraçtan sonra maksimum [_1] rakam içerebilir ama [_2] rakam içeriyor',
+ 'Total size of number must be less than or equal to [_1], but is [_2]', => 'Maksimum [_1] rakam içerebilir ama [_2] rakam içeriyor',
+ 'May have a maximum of [quant,_1,digit] after the decimal point, but has [_2]', => 'Ayraçtan sonra maksimum [_1] rakam içerebilir ama [_2] rakam içeriyor',
# H::F::Field::Integer
View
22 t/fields.t
@@ -509,4 +509,26 @@ $field->_set_input( 2100 );
$field->validate_field;
ok( $field->has_errors, '2100 makes the author really old' );
+# float
+
+$class = 'HTML::FormHandler::Field::Float';
+use_ok( $class );
+$field = $class->new( name => 'foat_test' );
+ok( defined $field, 'field built' );
+$field->_set_input( '2.0' );
+$field->validate_field;
+ok( !$field->has_errors, 'accepted 2.0 value' );
+$field->_set_input( '2.000' );
+$field->validate_field;
+ok( $field->has_errors, 'error for 3 decimal places' );
+is( $field->errors->[0], 'May have a maximum of 2 digits after the decimal point, but has 3', 'error message correct' );
+$field->size(4);
+$field->_set_input( '12345.00' );
+$field->validate_field;
+ok( $field->has_errors, 'error for size' );
+is( $field->errors->[0], 'Total size of number must be less than or equal to 4, but is 7', 'error message correct' );
+$field->_set_input( '12.30' );
+$field->validate_field;
+ok( $field->validated, 'field validated' );
+
done_testing;
View
12 util/messages
@@ -36,11 +36,6 @@
}
},
{
- 'Captcha' => {
- 'captcha_verify_failed' => 'Verification incorrect. Try again.'
- }
- },
- {
'Date' => {
'date_late' => 'Date is too late',
'date_early' => 'Date is too early'
@@ -62,6 +57,13 @@
}
},
{
+ 'Float' => {
+ 'float_needed' => 'Must be a number. May contain numbers, +, - and decimal separator \'[_1]\'',
+ 'float_precision' => 'May have a maximum of [quant,_1,digit] after the decimal point, but has [_2]',
+ 'float_size' => 'Total size of number must be less than or equal to [_1], but is [_2]'
+ }
+ },
+ {
'Integer' => {
'integer_needed' => 'Value must be an integer'
}

0 comments on commit 8cefb75

Please sign in to comment.