no error text when use inputTemplate
Opened this issue · 1 comments
mgrechanik commented
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 commented
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.