Yii2: how to use custom validation function for activeform?

前端 未结 12 1277
独厮守ぢ
独厮守ぢ 2020-12-25 14:18

In my form\'s model, I have a custom validation function for a field defined in this way

class SignupForm extends Model
{
    public function rules()
    {
          


        
12条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-25 14:39

    Try forcing the validation on empty field

    ['birth_date', 'checkDateFormat', 'skipOnEmpty' => false, 'skipOnError' => false],
    

    Also, make sure you don't assign id to your birth_date field in your view.

    If you do have id for your birth_date, you need to specify the selectors

    field($model, 'birth_date', ['selectors' => ['input' => '#myBirthDate']])->textInput(['id' => 'myBirthDate']) ?>
    

提交回复
热议问题