yii2yii2-advanced-appactive-form

yii2 ActiveForm numeric textfield


I've created an ActiveForm using yii2 like this:

                            <?=$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 it rendered a result of:

<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 make it < input type="number" .. and not text.. (so user could change value using browser up/down buttons). is there any way to do it?


Solution

  • You can use ->textInput(['type' => 'number'] eg :

    <?=$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)?>