symfony/symfony — Issue #3091: Incorrect Form Field Guessing And/Or Validation
Author: studip101
Created: 2012-01-11 13:15:44+00:00
State: open

Hi,

When I make a form from an entity class with this property:

```
/**
* @Assert\NotBlank()
* @Assert\Min("-.5")
* @Assert\Max(".5")
*/
protected $numericProperty;
```

Symfony adds a ```pattern=".{3,2}"``` attribute to the HTML `` in the view, which is obviously not right. The pattern attribute is still added even if I ```@Assert\Type("float")``` or ```@Assert\Type("numeric")```.

(Note that if I leave out the quotation marks in ```@Assert\Min``` and ```Assert\Max``` I get an error.)

If I explicitly specify the field as optional or as a number type when I add it to the form builder, then the ```pattern``` attribute goes away (as expected), but another problem crops up: I can't specify a positive number without a leading digit (e.g. ".3"). When I do so, I get the error:

> Expected argument of type "numeric", "boolean" given in vendor/symfony/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php at line 73

The validation constraints are working though: if I enter a number outside of -.5 and .5, I get the appropriate error, and .3 is accepted if I enter it as 0.3.

Both of the ```pattern``` attribute and the requirement for a leading 0 weren't behaviors I was expecting. But maybe I'm missing something?