Как проверить форму множественного ввода yii2

Я использовал многократную форму ввода с https://github.com/unclead/yii2-multiple-input/ здесь. когда я использую

                                        'options' => [
                                            'class' => 'input-priority',
                                            'required' => 'required'
                                        ],
                                        'attributeOptions' => [
                                            'enableClientValidation' => true,
                                            'validateOnChange' => true,
                                        ], 'enableError' => true,

Это отображает ошибку HTML5. Когда я комментирую выше, модель кода не проверяется Yii. Что я здесь не так делаю?

Код изнутри

<?= $form->field($model->contacts, 'grids')->widget(MultipleInput::className(), [
                                'allowEmptyList' => false,
                                'min' => 1,
                                'addButtonPosition' => MultipleInput::POS_HEADER,
                                'addButtonOptions' => ['class' => 'btn btn-info', 'label' => '<i class="fa fa-plus"></i>&nbsp;Add Contact'],
                                'removeButtonOptions' => ['class' => 'btn btn-default', 'label' => '<i class="fa fa-trash"></i>'],
                                'columns' => [
                                    [
                                        'name' => 'person_name',
                                        'title' => 'Person Name',
//                                        'options' => [
//                                            'class' => 'input-priority',
//                                            'required' => 'required'
//                                        ],
//                                        'attributeOptions' => [
//                                            'enableClientValidation' => true,
//                                            'validateOnChange' => true,
//                                        ], 'enableError' => true,
                                    ],
                                    [
                                        'name' => 'mobile',
                                        'title' => 'Mobile',
                                    ],
                                    [
                                        'name' => 'email',
                                        'title' => 'Email',
//                                        'options' => [
//                                            'class' => 'input-priority',
//                                            'required' => 'required'
//                                        ],
//                                        'attributeOptions' => [
//                                            'enableClientValidation' => true,
//                                            'validateOnChange' => true,
//                                        ], 'enableError' => true,
                                    ]
                                ]
                            ])->label(false); ?>

Код модели, который я указал public $grids; в модели и проверки ()

public function rules()
    {
        return [
            [['id', 'developer_id', 'person_name', 'email'], 'required'],
            [['id', 'developer_id'], 'integer'],
            [['person_name', 'email'], 'string', 'max' => 100],
            [['mobile'], 'string', 'max' => 15],
            [['id'], 'unique'],
            [['developer_id'], 'exist', 'skipOnError' => true, 'targetClass' => PropertyDeveloper::className(), 'targetAttribute' => ['developer_id' => 'id']],
            ['grids','validateGrids']
        ];
    }

    public function validateGrids($attribute)
    {
        $requiredValidator = new RequiredValidator();

        foreach($this->$attribute as $index => $row) {
            $error = null;
            $requiredValidator->validate($row['person_name'], $error);
            if (!empty($error)) {
                $key = $attribute . '[' . $index . '][person_name]';
                $this->addError($key, $error);
            }
        }
    }
}

Я хочу проверки модели

0 ответов

Другие вопросы по тегам