How to disable client side validation messages of

2019-05-28 06:52发布

We wish to remove the validation messages to appear on client side validation using activeform on Yii 2.0.

Tried:

$form = ActiveForm::begin(['clientOptions'=>['hideErrorMessage'=>false]]);

Getting:

Invalid Call – yii\base\InvalidCallException

Setting read-only property: yii\widgets\ActiveForm::clientOptions

On docs, the best I could found was: http://www.yiiframework.com/doc-2.0/yii-widgets-activeform.html#getClientOptions()-detail

I have no clue what "The Options" are, so I guessed "hideErrorMessage" due to Yii 1 experience.

Can you please advice, how can we programatically disable the error messages generated, without having to, either create a new template for showing the form, nor doing display:none; with css.

The full activeform call for your consideration:

$form = ActiveForm::begin(
        ['id' => $model->formName(),
            'enableClientValidation'=> true,
            'validateOnBlur'=>false,
            'validateOnType'=>true,
            'validationDelay'=> 1500,
            'clientOptions'=>['hideErrorMessage'=>false]
        ]);

The clientOptions was a try/guess.

Then, the form fields, an example:

<?= $form->field($model, 'first_name')->textInput()->label(false) ?>

标签: php yii2
1条回答
别忘想泡老子
2楼-- · 2019-05-28 07:38

Try this.

$form = ActiveForm::begin(['fieldConfig' => ['template' => '{label}{input}']]);
查看更多
登录 后发表回答