8000 "number" input type maps to "text" input type · Issue #8106 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

"number" input type maps to "text" input type #8106

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

Closed
tbriles opened this issue May 20, 2013 · 8 comments
Closed

"number" input type maps to "text" input type #8106

tbriles opened this issue May 20, 2013 · 8 comments

Comments

@tbriles
Copy link
tbriles commented May 20, 2013

There is even a comment in src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig stating:

"{# type="number" doesn't work with floats #}",

which isn't true. I'd recommend setting step="any" as a default.

@barryvdh
Copy link
Contributor
barryvdh commented May 7, 2015

Still no reply after 2 years?

I would agree that the number type rendering as text feels a bit counter-intuitive..

Or should this be closed in favor of #10240?

@ghost
Copy link
ghost commented May 7, 2015

it doesn't render as
8000 <input type="text" />. I see <input type="number" />

@dolbertz
Copy link

To clearify: Symfony 3.0.3 renders NumberType as type="text", and IntegerType as type="number"

@AxxiD
Copy link
AxxiD commented May 19, 2016

This issue is still persistant in v3.0.6 and was originally marked to be changed in 3.0.
Also: See my comment on #10240 (comment)

@ianfp
Copy link
ianfp commented Feb 16, 2018

You can always override the default Twig template for NumberType like so:

In config.yml:

twig:
    form_theme:
        - "form/fields.html.twig"

In templates/form/fields.html.twig:

{%- block number_widget -%}
    {# https://github.com/symfony/symfony/issues/8106 #}
    {%- set type = type|default('number') -%}
    {{ block('form_widget_simple') }}
{%- endblock number_widget -%}

This seems to work, but I've only just now started testing it.

@laufhannes
Copy link

The snippet provided by @ianfp does not work for us as alternative. If browser and php language settings do not match, problems may occur. For German numbers Symfony does automatically render value="0,3" which is ignored by a browser with English settings (as it expects . as decimal point).

@xabbuh
Copy link
Member
xabbuh commented Feb 16, 2019

will be implemented in #30267

@fabpot fabpot closed this as completed Feb 21, 2019
fabpot added a commit that referenced this issue Feb 21, 2019
…" (xabbuh)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Form] add option to render NumberType as type="number"

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8106
| License       | MIT
| Doc PR        | symfony/symfony-docs#10997

Commits
-------

42e8f5e add option to render NumberType as type="number"
@Volmarg
Copy link
Volmarg commented Nov 27, 2019

I will just leave this here as it took me like 2 min to find out how and where:

            ->add('Price', NumberType::class, [
                "attr" => [
                    "min"  => 0.1,
                ],
                'label' => $this->app->translator->translate('forms.MyPaymentsProductsType.labels.price'),
                'html5' => true, // this is the part that converts text to number type
            ])

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

No branches or pull requests

0