如何在 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}']]);