mgrechanik/yii2-activefield-additional-error 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mgrechanik/yii2-activefield-additional-error

最新稳定版本:1.0.1

Composer 安装命令:

composer require mgrechanik/yii2-activefield-additional-error

包简介

Adding special span to activefield with bootstrap error class .is-invalid to desired place of field template

README 文档

README

What is it about?

Bootstrap 4 and 5 are expecting html like this to decorate validation error:

<input type="text" id="eventform-datetime" class="form-control is-invalid" name="EventForm[datetime]" aria-required="true">
<div class="invalid-feedback">Error message</div>

Element with div.invalid-feedback is supposed to be on the same level with your input.is-invalid.

But sometimes when we are using any widgets or custom template we get html like this:

<div class="some-plugin-wrapper">
  <input type="text" id="eventform-datetime" class="form-control is-invalid" name="EventForm[datetime]" aria-required="true">
</div>  
<div class="invalid-feedback">Error message</div>

, so our error message is not shown.

Of cource you can make div.invalid-feedback visible by css for this page.

But if that does not suit you, this library propose another solution.

We are adding special <span> to a field template right before {error} part. And we synchronize this <span> with the input field so it gets .is-invalid class when input does

Installing

Installing through composer::

The preferred way to install this library is through composer.

Either run

composer require --prefer-dist mgrechanik/yii2-activefield-additional-error 

or add

"mgrechanik/yii2-activefield-additional-error " : "~1.0.0"

to the require section of your composer.json.

How to use

in your view file, say it is _form.php

use mgrechanik\additionalerror\AdditionalErrorBehavior;

<div class="event-form-form">

    <?php $form = ActiveForm::begin([
            'id' => 'event-create-form',
            // Adding behavior
            'as adderror' => [
                'class' => AdditionalErrorBehavior::class,
            ]
    ]); ?>

    <?= $form->field($model, 'datetime', [
            // Adding this hidden span before error block 
            'template' => "{label}\n{input}\n{hint}\n" . $form->getAdditionalErrorSpan($model, 'datetime') . "\n{error}"
    ])->hint('Some hint')
      ->widget(/* Some complicated widget creates a wrapper for the {input} part... */)

It will work for both server and client side.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2024-12-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固