-
-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Description of the problem:
For example, say we have a text field that is used to store float numbers and our application is in french (yes, it's my native language :). In database, it is stored as float, like 4112.156
. In a french notation, this number should appear as 4 112,156
.
In that case, if you want to do things the right way you expect the user to enter numbers in a french notation. So you add an input filter and a validator in your form like this:
'my_localized_number_field' => array(
'allow_empty' => true,
'required' => false,
'filters' => array(
array(
'name' => 'NumberParse',
'options' => array(
'locale' => 'fr_FR',
'style' => \NumberFormatter::DECIMAL,
),
),
),
'validators' => array(
array(
'name' => 'IsFloat',
'options' => array(
'locale' => 'fr_FR',
),
),
),
),
This input filter specification verifies that the user is entering a number in the french notation. For example, if he tries to enter 4112.156
, it will be rejected.
If the user enters 4 112,156
, the value will be accepted, then parsed to a float and finally saved in database as a real float type 4112.156
.
Good!
Now the user want to modify this value and opens the form again. When the form will be populated by the database row, the field value will be written in the native float notation.
Using the original formRow view helper, as the field is filled with a native float notation, when the user will try to submit the form again without any modification, it will be rejected because the value is 4112.156
and the form expects 4 112,156
.
No way!
As suggested there, can you see my issue neilime/zf2-twb-bundle#144 where I offer a solution to this problem. I think a similar mechanism should be included in zf2 in order to avoid adding 5 lines of code for each i18n related fields as soon as an application is multi-lingual.
Thank you.
Originally posted by @berturion at zendframework/zend-form#10