我有一个学院的席位分配实体,有3个字段,总席位,男性席位,女性席位。场景是所有座位都是男性或女性,或者它可以在男性和女性之间分配。
明确地说,我的问题是:我想检查用户是否至少选择了所需的两个字段之一(maleSeat 和 femaleSeat)
->add('maxSeats', 'integer', array(
'label' => ucwords('max Seats'),
'required' => true, // Choose if it's required or not
'constraints' => $constraints['maxSeats'],
'invalid_message' => 'You entered an invalid value, it should include %num%',
'sonata_help' => 'Here some help text!!!',
'attr' => array(
'class' => 'form-control',
'help' => 'My Help Message',
),
'label_attr' => array(
'class' => 'control-label'
)
))
->add('maleSeats', 'integer', array(
'label' => ucwords('male Seats'),
'required' => true, // Choose if it's required or not
'constraints' => $constraints['maleSeats'],
'invalid_message' => 'You entered an invalid value, it should include %num%',
'attr' => array(
'class' => 'form-control'
),
'label_attr' => array(
'class' => 'control-label'
)
))
->add('femaleSeats', 'integer', array(
'label' => ucwords('female Seats'),
'required' => true, // Choose if it's required or not
'constraints' => $constraints['femaleSeats'],
'invalid_message' => 'You entered an invalid value, it should include %num%',
'attr' => array(
'class' => 'form-control'
),
'label_attr' => array(
'class' => 'control-label'
)
))
$constraints = array(
'maxSeats' => array(
new Assert\NotBlank(),
new Assert\Range(array(
'min' => 1,
'minMessage' => 'Min Seats is 1'
)),
new Assert\Regex(array(
'pattern' => '/[0-9]/',
'message' => 'Total Seats Should Only be a Positive Number',
)),
),
'maleSeats' => array(
new Assert\NotBlank(),
new Assert\Range(array(
'min' => 1,
'minMessage' => 'Min Seats is 1'
)),
new Assert\Length(array(
'min' => 1,
'max' => 30,
'minMessage' => 'The min Seats must be more than 6 and less than 1 characters long',
'maxMessage' => 'The min Seats must be more than 6 and less than 30 characters long',
)),
new Assert\Regex(array(
'pattern' => '/[0-9]/',
'message' => 'Total Seats Should Only be a Positive Number',
)),
),
'femaleSeats' => array(
new Assert\NotBlank(),
new Assert\Range(array(
'min' => 1,
'minMessage' => 'Min Seats is 1'
)),
new Assert\Length(array(
'min' => 1,
'max' => 30,
'minMessage' => 'The min Seats must be more than 6 and less than 1 characters long',
'maxMessage' => 'The min Seats must be more than 6 and less than 30 characters long',
)),
new Assert\Regex(array(
'pattern' => '/[0-9]/',
'message' => 'Total Seats Should Only be a Positive Number',
)),
),
);
我知道它可以通过 jquery 的东西来处理,但我不想在这里涉及 jquery 和其他东西,我如何使用 symfony 内置组件来实现这一点。