如何在 Yii 2 中禁用 activeform 的客户端验证消息? [英] How to disable client side validation messages of activeform in Yii 2?

查看:29
本文介绍了如何在 Yii 2 中禁用 activeform 的客户端验证消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望在 Yii 2.0 上使用 activeform 删除出现在客户端验证中的验证消息.

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

尝试过:

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

获取:

无效调用 – yii\base\InvalidCallException

Invalid Call – yii\base\InvalidCallException

设置只读属性:yii\widgets\ActiveForm::clientOptions

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

在文档上,我能找到的最好的是:http://www.yiiframework.com/doc-2.0/yii-widgets-activeform.html#getClientOptions()-detail

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

我不知道选项"是什么,所以我猜测hideErrorMessage"是由于 Yii 1 的经验.

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

能否请您指教,我们如何以编程方式禁用生成的错误消息,而不必创建用于显示表单的新模板,也不必执行 display:none;使用 CSS.

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.

供您考虑的完整 activeform 电话:

The full activeform call for your consideration:

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

clientOptions 是一个尝试/猜测.

The clientOptions was a try/guess.

然后是表单域,一个例子:

Then, the form fields, an example:

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

推荐答案

试试这个.

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

这篇关于如何在 Yii 2 中禁用 activeform 的客户端验证消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆