1

I'm trying to make a form in yii2 accept big numbers like currency . I want the number to be seperated for example 10000000 seems like that 10.000.000 . I search and find that there is something called auto numiric I use it but I got this error

<?=$form->field($model, 'num')->widget(\extead\autonumeric\AutoNumeric::classname(), [
                'pluginOptions' => [
                    'aSep' => ' ',
                    'mDec' => 0
                ]
            ]);?>

    Not instantiable – yii\di\NotInstantiableException
Failed to instantiate component or class "yii\bootstrap\BootstrapAsset".
↵
Caused by: ReflectionException
Class yii\bootstrap\BootstrapAsset does not exist
in E:\xam\htdocs\basic\vendor\yiisoft\yii2\di\Container.php at line 507

if I diddn't use auto numiric

<?= $form->field($model,'num')?>

the error disappear can any body help ????

Fahd
  • 17
  • 1
  • 6

1 Answers1

0

It looks like extead/yii2-autonumeric requires yiisoft\yii-bootstrap extension which uses Bootstrap 3.

You can install missing extension through composer:

composer require --prefer-dist yiisoft/yii2-bootstrap

Or you can add it in your composer.json and then run composer update to install it.

Edit: actually, I've missed that yii2-bootstrap4 and yii2-bootstrap5 extensions uses different namespaces so for yii2-autonumeric extension to work you have to install bootstrap 3 extension. If you can't use bootstrap 3, you should probably switch to another extension for formating values in inputs. For example kartik-v/yii2-number allows you to set what version of bootstrap should be used.

Michal Hynčica
  • 5,038
  • 1
  • 12
  • 24
  • 1
    in my composer.json I have yiisoft\yii2-bootstrap4 in the require section – Fahd Jun 15 '22 at 10:31
  • @Fahd sorry, I've missed that bootstrap4 and bootstrap5 extensions uses different namespace. So you have to use bootstrap 3 extension if you want to use `yii2-autonumeric`. I've edited my answer to reflect that and suggested alternative extension for number formating in inputs. – Michal Hynčica Jun 15 '22 at 13:55
  • I used composer require --prefer-dist yiisoft/yii2-bootstrap to download bootstrap2 and the code works thanks alot but I wonder how to use kartik-v/yii2-number. I download it via composer but I didn't know how to update my code to use it – Fahd Jun 15 '22 at 17:16
  • There is a link to yii2-number extension documentation with examples in my answer. The way to use it is basically same as with AutoNumeric widget you just need to adjust class and options. – Michal Hynčica Jun 15 '22 at 19:37