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

no error text when use inputTemplate #85

Open
mgrechanik opened this issue May 8, 2024 · 1 comment
Open

no error text when use inputTemplate #85

mgrechanik opened this issue May 8, 2024 · 1 comment

Comments

@mgrechanik
Copy link

mgrechanik commented May 8, 2024

What steps will reproduce the problem?

First working code:

                  <?= $form->field($model, 'sigmapercent', [
                      'template' => "{label}\n{input}\n{hint}\n{error}"
                 ])->textInput() ?></div>

works like usual in Yii2.

And now I try to add suffix to the field

<?= $form->field($model, 'sigmapercent', [
                      'inputTemplate' => '<div class="input-group">{input}
                          <span class="input-group-text">%</span>
                      </div>',
                      'template' => "{label}\n{input}\n{hint}\n{error}"
                 ])->textInput()

What is the expected result?

I see a suffix all right

What do you get instead?

But when I put incorrect value in the field, I do not see error message under the field. Only field's border becomes red. (without reloading the page, only js validation)

Additional info

Q A
Yii vesion 2
PHP version 8
Operating system ubuntu
@micro-maureen
Copy link

Your layout is not right, the correct layout is shown here - https://getbootstrap.com/docs/5.0/forms/validation/#server-side

{error} should be inside the input group, and the input group should have the .has-validation class:

<?= $form->field($model, 'sigmapercent', [
                      'inputTemplate' => '{input}<span class="input-group-text">%</span>',
                      'template' => '{label}<div class="input-group has-validation">{input}{error}</div>',
                 ])->textInput()

Note: I have excluded {hint} from this example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants