Yii2:如何在输入字段之前和之后添加符号 [英] Yii2: How add a symbol before and after an input field

查看:52
本文介绍了Yii2:如何在输入字段之前和之后添加符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在输入文本的前后添加符号?就像图像附件一样.

How can I add a symbol before and after of an input text? Just like the image attach.

我的代码:

<?= $form->field($model_product, 'percent')->textInput(['class'=>'smallInputFormInline'])->label('Percent',['class'=>'labelModalFormInline']) ?>

<?= $form->field($model_product, 'percent_all')->textInput(['class'=>'smallInputFormInline'])->label('Percent All',['class'=>'labelModalFormInline']) ?>

<?= $form->field($model_product, 'amount')->textInput(['class'=>'smallInputFormInline'])->label('Amount',['class'=>'labelModalFormInline']) ?>

解决方案

我按照ActiveForm文档修改了我的代码,它可以正常工作!

I modify my code following ActiveForm documentation and it works!

代码已修改:

<?= $form->field($model_product, 'amount', ['template' => '{label}${input}'])->textInput(['class'=>'smallInputFormInline'])->label('Amount',['class'=>'labelModalFormInline']) ?>

推荐答案

例如,您可以使用ActiveForm字段"template" 选项向输入中添加一些插件.

For example you can add some addons to input using ActiveForm field "template" option.

例如输入末尾的插件:

<?= $form->field($model_product, 'percent', [
            'template' => '{beginLabel}{labelTitle}{endLabel}<div class="input-group">{input}
            <span class="input-group-addon">%</span></div>{error}{hint}'
        ]); ?>

这篇关于Yii2:如何在输入字段之前和之后添加符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆