Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 817
Ofershap Avatar asked Nov 09 '15 12:11

Ofershap


2 Answers

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)?>
like image 143
Touqeer Shafi Avatar answered Oct 15 '22 14:10

Touqeer Shafi


Try this . it worked for me

<?= $form->field($model, 'amount')->textInput(['type' => 'number']) ?>
like image 22
Shuhad zaman Avatar answered Oct 15 '22 14:10

Shuhad zaman