Symfony: Feature: Add min and max to integer type in Form component.

Created on 8 Mar 2012  ·  3Comments  ·  Source: symfony/symfony

It would be awesome to add a the min an max attribute to the integer type in the Form component. I see the usage in a controller happening like this:

$formBuilder = $this->createFormBuilder(array())
    ->add('someIntegerField', 'integer', array('min' =>2, 'max' =>5,));

Then the form rendering widget would add the min or max fields to the html input tag.
<input type="number" id="form_someIntegerField" name="form[someIntegerField]" min="2" max="5">

Most helpful comment

array('attr' => array('min' => ...)) should work. If it is the case you can open a PR to improve the doc.

Note: min/max should be guessed from your validation constraints but I remember of a defect for integers.

All 3 comments

array('attr' => array('min' => ...)) should work. If it is the case you can open a PR to improve the doc.

Note: min/max should be guessed from your validation constraints but I remember of a defect for integers.

Thanks vicb! That worked perfectly. I don't think that was in the documentation...

Excelet !!!!

Was this page helpful?
0 / 5 - 0 ratings