Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model attribute has error, but DatePicker doesnt display it #83

Open
Mapteg34 opened this issue Dec 25, 2018 · 7 comments
Open

Model attribute has error, but DatePicker doesnt display it #83

Mapteg34 opened this issue Dec 25, 2018 · 7 comments
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug

Comments

@Mapteg34
Copy link

Mapteg34 commented Dec 25, 2018

What steps will reproduce the problem?

$model->addError('date', 'test error');
echo $form->field($model, 'date')->widget(DatePicker::class);

What's expected?

Input with datepicker and error text

What do you get instead?

Input with datepicker with no error

How to fix it?

@samdark samdark added the type:bug Bug label Dec 30, 2018
@BloodyAltair
Copy link

BloodyAltair commented Apr 13, 2019

I've encountered the same problem with DatePicker widget and Bootstrap4.
I've tested it with other yii2-bootstrap4 fields and widgets - it is a problem of DatePicker (see yiisoft/yii2-bootstrap4#126)
If i submit invalid form data, error message does not shown
изображение

@buttflattery
Copy link

So is it related to yii2-bootstrap4 and you are talking about the ActiveForm frontend validation @BloodyAltair ?

@BloodyAltair
Copy link

@buttflattery Its related to compatibilitiy between yii2-bootstrap4 and jui/datepicker. I am talking about server-side validation errors, but client-validation errors also may be affected, I didn't tested it yet

@acmepy
Copy link

acmepy commented Feb 20, 2020

if yii\jui\Widget extends from \yii\widgets\InputWidget, at least with datepicker and autocomplete it works

class Widget extends \yii\widgets\InputWidget #\yii\base\Widget

@mmonem
Copy link

mmonem commented Jan 3, 2021

As a temporary workaround, until this bug can be fixed, a manual setting of the has-error class (or is-invalid in case of bootstrap4) can be a solution:

<?= $form->field($model, 'date_from')->widget(DatePicker::classname(), [
    ...
    'options' => [
        ...
        'class' => 'form-control' . ($model->hasErrors('date_from') ? ' is-invalid' : '')
        ...
    ],
    ...
]) ?>

@bizley bizley added the status:ready for adoption Feel free to implement this issue. label Jan 4, 2021
@alanshijo
Copy link

alanshijo commented Dec 1, 2023

<?= $form->field($model, 'dob')->widget(DatePicker::class, [
    'options' => ['placeholder' => 'Enter birth date'],
    'pluginOptions' => [
        'autoclose' => true,
        'format' => 'yyyy-mm-dd',
    ]
])->error(['class' => 'invalid-feedback d-block']); ?>

Try appending the

->error(['class' => 'invalid-feedback d-block']);

at the end of the line.
This fixed mine.

@mgrechanik
Copy link

Hi. I created a library to solve these sort of problems.
Met this problem for another widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug
Projects
None yet
Development

No branches or pull requests

9 participants