Skip to content

[Form] Add options "min" and "max" to NumberType #6732

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
romaricdrigon opened this issue Jan 14, 2013 · 12 comments
Closed

[Form] Add options "min" and "max" to NumberType #6732

romaricdrigon opened this issue Jan 14, 2013 · 12 comments

Comments

@romaricdrigon
Copy link
Contributor

Hi,

At the moment, using the Range validation constraint, we can set up a min & max for a numeric value in an entity property.

Html5 offers min & max attributes for number inputs, so we can also enforce this client-side in any form:

$builder
    ->add('aNumber', 'number', array(
            'attr' => array('min' => 1, 'max' => 100)
    ))

It may be nice to offer min & max options for number field type. It seems pretty logical, as some other fields already have such attributes (ie max_length for text fields).

The syntax may be:

$builder
    ->add('aNumber', 'number', array(
            'min' => 1,
            'max' => 100
    ))

These attributes will be used client-side & the submitted object will be validated too.

What do you think?
I'm ok about contributing the code (& tests & doc), but I wanted the idea to be reviewed first.

@thewholelifetolearn
Copy link

+1
I think it is a good idea. The 2nd syntax is a good proposal. It would have the same architecture then "text" field.

@jameshalsall
Copy link
Contributor

+1 for this idea, would be great as a convenience

@webmozart
Copy link
Contributor

In fact max_length should be removed (see #7148) so I don't think that we should add new options. But we should indeed add functionality to guess the "min" and "max" attributes for the number type (in case Min, Max or Range is used). Marking this as feature request.

@stof
Copy link
Member

stof commented Feb 21, 2013

@bschussek why shouldn't we try to guess them to improve the client side validation ? Some other client-side validation attributes are already guessed.

@webmozart
Copy link
Contributor

Could it be you misread my post? :)

@stof
Copy link
Member

stof commented Feb 21, 2013

hmm, indeed.

@fnagel
Copy link
Contributor

fnagel commented Aug 20, 2013

+1 subscribe

@vmattila
Copy link

vmattila commented Nov 8, 2014

This is definitely useful here (+1). Wouldn't it make sense to also change number field to render as HTML5 number instead of text? This also relates to ticket #11979 .

@hhamon
Copy link
Contributor

hhamon commented Apr 19, 2015

+1

@Tobion
Copy link
Contributor

Tobion commented Apr 19, 2015

What's the point of adding these options instead of using attr? All attributes that have no backend logic have actually been removed, e.g. max_length, pattern, read_only. So I'm rather -1 on doing the same thing with two different approaches.

@webmozart
Copy link
Contributor

As I said, I'm also against adding options if we can also use the attributes. See #15014.

@mohamedchibani
Copy link

thank you

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

10 participants