Yii2 ActiveForm numeric text field

I created ActiveForm using yii2 as follows:

                            <?=$form->field($item, 'finalPrice', [
                                'options' => [
                                    'tag' => 'div',
                                    'class' => '',
                                ],
                                'template' => '<span class="col-md-2 col-lg-2"><label class="control-label">Final item price</label>{input}{error}</span>'
                            ])->textInput([
                                 // ** i want numeric value **
                            ])->label(false)?>

and he gave the result:

<span class="col-md-2 col-lg-2"><label class="control-label">Final item price</label><input type="text" id="item-finalprice" class="form-control" name="Item[finalPrice]"><p class="help-block help-block-error"></p></span>

Now I want to do this & lt; input type = "number" .., not text .. (so that the user can change the value using the browser buttons up / down). is there any way to do this?

+6
source share
2 answers

You can use ->textInput(['type' => 'number']for example:

<?=$form->field($item, 'finalPrice', [
                                'options' => [
                                    'tag' => 'div',
                                    'class' => '',
                                ],
                                'template' => '<span class="col-md-2 col-lg-2"><label class="control-label">Final item price</label>{input}{error}</span>'
                            ])->textInput([
                                 'type' => 'number'
                            ])->label(false)?>
+23
source

Try this. it worked for me

<?= $form->field($model, 'amount')->textInput(['type' => 'number']) ?>
0
source

Source: https://habr.com/ru/post/1615042/


All Articles