symfony - textbox is not displayed when I use integer as field type in symfony2 -
i using integer type field in form type of symfony2. code follows:
$builder->add('phonenumber', 'integer',array( 'required' => true, 'constraints' => array( 'pattern' => '/^[0-9]\d*$/', new length(array( 'min' => 10, 'max' => 20 )) )));
although phone number field validated, uparrow , downarrow displayed , if click on getting numbers -1 instead of textbox. if put number field type textbox dispayed field not validated. grateful if me out issue. in advance.
integer
fields aren't used (only literal integers, , not always). phone number you'd want text
field.
update
use symfony\component\validator\constraints\regex; use symfony\component\validator\constraints\length; $builder->add('phonenumber', 'text', array( 'required' => true, 'constraints' => array( new regex(array( 'pattern' => '/^[0-9]*$/' )) , new length(array( 'min' => 10, 'max' => 20 )) ) ));
@rufinus's answer may better option.
Comments
Post a Comment