dsdukbc60905239 2019-05-29 08:35
浏览 433

如何自定义验证错误消息以显示在Yii2的工具提示中?

I am using ActiveForm of yii2 and I want to customize the validation errors. I want to display errors on tooltip.

This is my form

<?= $form = ActiveForm::begin(['id' => 'login-form','method'=>'post']); ?>
    <?= 
        $form->field($model, 'email')
            ->textInput([
                'class'=>'form-control login_email',
                'placeholder'=>'Email'
                /*'onfocus'=>"this.value = '';",
                "onblur"=>"if (this.value == '') {
                    this.value = 'Email';
                }"*/
            ])
            ->label(false);
    ?>
    <?= 
        $form->field($model, 'password')
            ->passwordInput([
                'class'=>'form-control',
                'placeholder'=>'Password'
            ])
            ->label(false);
    ?>
    <input type="text" name="hidden" value="login" hidden="true">
    <p class="forgot">
        <a href="<?= Yii::$app->urlManager->createUrl(['site/request-password-reset']); ?>">
            Forgot Password?
        </a>
    </p>

    <div class="form-group">
        <?= Html::submitButton('Log In', ['class' => 'sign-in','name' => 'login-button']) ?>
    </div>
<?php ActiveForm::end(); ?>

Please tell me if anyone has idea about this.

  • 写回答

1条回答 默认 最新

  • doutao8774 2019-05-30 11:06
    关注

    Update error message in form template like below

      $form = ActiveForm::begin([
      'id' => 'login-form',
      'options' => ['enctype' => 'multipart/form-data'],
       'fieldConfig' => ['template' => "<div class=\"input-cover\"><div class=\"tooltip\">{error}</div>
    {label}
    {input}</div>",
      'inputOptions' => ['class' => 'input-control'],
                        ],
              ]);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程