How to disable client side validation messages of activeform in Yii 2?

心已入冬 提交于 2019-12-10 11:24:59

问题


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) ?>

回答1:


Try this.

$form = ActiveForm::begin(['fieldConfig' => ['template' => '{label}{input}']]);


来源:https://stackoverflow.com/questions/32372259/how-to-disable-client-side-validation-messages-of-activeform-in-yii-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!