haifahrul/yii2-autonumeric

autoNumeric是一个jQuery插件,可以在表单输入时自动格式化货币和数字。

安装次数: 280

依赖关系: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 1

开放问题: 1

类型:yii2-extension

1.2.0 2016-05-27 18:12 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:47:32 UTC


README

autoNumeric是一个jQuery插件,可以在表单输入时自动格式化货币和数字。

Total Downloads

安装

安装此扩展的首选方式是通过composer

运行以下命令:

php composer.phar require --prefer-dist haifahrul/yii2-autonumeric "*"

或者在您的composer.json文件的require部分添加以下内容:

"haifahrul/yii2-autonumeric": "*"

格式化设置(可选)

默认使用Yii::$app->formatter的thousandSeparator和decimalSeparator,您可以在配置文件中进行设置,如下所示:

'components' => [
    'formatter' => [
        'class' => 'yii\i18n\formatter',
        'thousandSeparator' => '.',
        'decimalSeparator' => ',',
    ]
]

使用方法

扩展安装完成后,只需在您的代码中使用即可

以下列出了完整的选项列表。有多种方式更改这些选项。要将"123456789.00"格式化为"Rp. 123.456.789",可以执行以下操作:

<?= $form->field($model, 'price')->widget(\haifahrul\autonumeric\AutoNumeric::classname(), [
        'value' => $model->price,
        'options' => [
            'id' => 'your-id',
            'class' => 'your-class',
            'readonly' => true,
            'disabled' => true,
        ],
        'pluginOptions' => [
            'aSep' => '.', // if you using Formatter Settings, this is not necessary
            'aDec' => ',', // if you using Formatter Settings, this is not necessary
            'aSign' => 'Rp. ',
            'mDec' => '0' // default 2
        ]
    ]);
?>

其他选项,请参阅https://yiiframework.cn/doc-2.0/guide-helper-html.html

有关示例和其他插件选项,请参阅autoNumeric文档:https://github.com/BobKnothe/autoNumeric

感谢extead。https://github.com/extead