Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying filters to form elements with i18n validators on rendering with form view helpers #37

Open
michalbundyra opened this issue Jan 15, 2020 · 0 comments

Comments

@michalbundyra
Copy link
Member

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7511
User: @berturion
Created On: 2015-05-11T08:54:59Z
Updated At: 2015-11-06T21:38:46Z
Body
Hello,
I am facing a problem when rendering forms containing existing values that have i18n input filters.

Here is an example with a Float:
1 - I fill a form with a float in french format (comma as decimal separator) and submit it
2 - The form validates the float in french format => OK
3 - I reopen the form to edit the float using FormRow view helper
4 - The float is rendered in english format (dot as decimal separator)
5 - If I submit the form as is, with no modification, the float field get an input validation error because the float has been redered in english format => KO

My question is: Why couldn't we set a 'filters' option in the form element declaration and render it correctly in the FormRow View Helper and others (applying the filters before rendering) like this?

    $this->add(array(
        'name' => 'price',
        'type' => 'text',
        'options' => array(

        ),
        'filters' => array(
            array(
                'name' => 'NumberFormat',
                'locale' => 'fr_FR',
                'style' => \NumberFormatter::DECIMAL
            )
        ),
    ));

In that way, we could render i18n form values in the same way as they should be entered.

What do you think ?

EDIT:

The workaround I found is this:

$price = $form->get('price');
$origValue = $price->getValue();
$price->setValue($this->numberFormat($origValue, \NumberFormatter::DECIMAL, \NumberFormatter::TYPE_DEFAULT, 'fr_FR'));
echo $this->formRow($price);

But I would really want to reduce view scripts and be able to use this simple line:

$this->formRow($form->get($price))


Originally posted by @GeeH at zendframework/zend-form#91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant