Symfony2: How to validate an input field is not-blank, only when checkbox is true?

后端 未结 3 1742
日久生厌
日久生厌 2020-12-30 14:51

Within Symfony2 how to validate an inputfield is not-blank, only when the value of a checkbox is 1 (True) - otherwise blank is allowed?

To be more precise, I have a

3条回答
  •  余生分开走
    2020-12-30 15:09

    could you do something like this ?

    /**
     * @Assert\True()
     */
    public function customValidate()
    {
        return (!$this->checkboxField) or (strlen($this->inputField) > 0);
    }
    

提交回复
热议问题