Closed
Description
#Customer.php
class Customer {
# (...)
/**
* @var string $phone
* @Assert\NotBlank()
* @Assert\Regex("/^\(\d{2}\) \d{4}-\d{4}$/")
* @ORM\Column(name="phone", type="string", length=14)
*/
private $phone;
# (...)
}
#CustomerType.php
class CustomerType extends AbstractType
{
# (...)
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('phone', null, array('label' => 'Telefone'))
;
}
# (...)
}
HTML Result:
<input type="text" id="paggy_admin_customer_phone" name="paggy_admin_customer[phone]" required="required" maxlength="14" class="input-text">
Workaround: If I add the "pattern" property, duplicating the code of entity, it works as expected:
#CustomerType.php
class CustomerType extends AbstractType
{
# (...)
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->->add('phone', 'text', array('label' => 'Telefone', 'pattern' => '^\
(\d{2}\) \d{4}-\d{4}$'))
;
}
# (...)
}
HTML Result:
<input type="text" id="paggy_admin_customer_phone" name="paggy_admin_customer[phone]" required="required" maxlength="14" pattern="^\(\d{2}\) \d{4}-\d{4}$" class="input-text">
Thanks!