Symfony 表单类型中仅允许0-100作为百分比值
我的表单中有一个百分比字段,我希望它的数值在0到100之间。否则我如何强制它并返回验证 目前我甚至可以输入100.10,这是错误的 注意:允许0.00和100.00 谢谢 实体:Symfony 表单类型中仅允许0-100作为百分比值,symfony,Symfony,我的表单中有一个百分比字段,我希望它的数值在0到100之间。否则我如何强制它并返回验证 目前我甚至可以输入100.10,这是错误的 注意:允许0.00和100.00 谢谢 实体: /** * @var decimal * @ORM\Column(type="decimal", precision=5, scale=2) */ protected $vatRate; ->add( 'vatRate', 'percent', array('type' => 'integer',
/**
* @var decimal
* @ORM\Column(type="decimal", precision=5, scale=2)
*/
protected $vatRate;
->add(
'vatRate',
'percent',
array('type' => 'integer', 'attr' => array('min' => '0', 'max' =>` '100'))
)
表单类型:
/**
* @var decimal
* @ORM\Column(type="decimal", precision=5, scale=2)
*/
protected $vatRate;
->add(
'vatRate',
'percent',
array('type' => 'integer', 'attr' => array('min' => '0', 'max' =>` '100'))
)
向实体中添加一个
use Symfony\Component\Validator\Constraints as Assert;
/* ... */
/**
* @var decimal
* @ORM\Column(type="decimal", precision=5, scale=2)
* @Assert\Range(
* min = 0,
* max = 100,
* minMessage = "Min % is 0",
* maxMessage = "Max % is 100"
* )
*/
protected $vatRate;
向实体中添加一个
use Symfony\Component\Validator\Constraints as Assert;
/* ... */
/**
* @var decimal
* @ORM\Column(type="decimal", precision=5, scale=2)
* @Assert\Range(
* min = 0,
* max = 100,
* minMessage = "Min % is 0",
* maxMessage = "Max % is 100"
* )
*/
protected $vatRate;
在实体中使用范围约束:
在实体中使用范围约束:
错误:选项“type”的值为“percent”,但应为“fractal”、“integer”中的一个。是的,对不起,在我匆忙中,我没有看到您已经在使用percent类型,所以我刚刚删除了该建议。错误:选项“type”的值为“percent”,但应为“fractal”、“integer”中的一个。是的,对不起,在我匆忙中,我没有看到您已经在使用百分比类型,所以我只是删除了该建议。