Search code examples
yii2formatcurrencyautonumeric.js

Failed to instantiate component or class "yii\bootstrap\BootstrapAsset"


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 ????


Solution

  • 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.