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

Related issues

jpresley23 picture jpresley23  路  3Comments

tdesvenain picture tdesvenain  路  3Comments

kherrera-ebsco picture kherrera-ebsco  路  3Comments

HappyJiJi picture HappyJiJi  路  3Comments

FRAGnatt picture FRAGnatt  路  3Comments