https://github.com/mgrechanik/yii2-activefield-additional-error
Adding special span to activefield with bootstrap error class .is-invalid to desired place of field template
https://github.com/mgrechanik/yii2-activefield-additional-error
activefield activeform bootstrap4 bootstrap5 yii2
Last synced: about 2 months ago
JSON representation
Adding special span to activefield with bootstrap error class .is-invalid to desired place of field template
- Host: GitHub
- URL: https://github.com/mgrechanik/yii2-activefield-additional-error
- Owner: mgrechanik
- License: other
- Created: 2024-12-10T10:58:04.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-10T12:26:36.000Z (6 months ago)
- Last Synced: 2025-03-26T20:51:30.157Z (2 months ago)
- Topics: activefield, activeform, bootstrap4, bootstrap5, yii2
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Additional span with error class for ActiveField
## What is it about?
Bootstrap 4 and 5 are expecting ```html``` like this to decorate validation error:
```html
Error message
```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:
```html
Error message
```
, 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 `````` to a field template right before ```{error}``` part. And we **synchronize** this `````` 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```
```php
use mgrechanik\additionalerror\AdditionalErrorBehavior;'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.