MEM
MEM

Reputation: 31407

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

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

Upvotes: 2

Views: 7308

Answers (1)

GAMITG
GAMITG

Reputation: 3818

Try this.

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

Upvotes: 7

Related Questions