atk14 / decimal-field
限制数字位数和小数位数的字段
v1.0.3
2024-07-18 08:19 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- atk14/core: dev-master
- atk14/forms: dev-master
- atk14/tester: *
This package is auto-updated.
Last update: 2024-09-18 08:48:32 UTC
README
限制数字位数和小数位数的字段。
DecimalField非常适合例如输入价格。
在ATK14应用程序中的使用
在表单中
<?php
// file: app/forms/products/create_new_form.php
class CreateNewForm extends ApplicationForm {
function set_up(){
// ...
$this->add_field("price", new DecimalField([
"label" => "Price",
"max_digits" => 7,
"decimal_places" => 2,
"min_value" => 0,
]));
// ...
}
}
此字段的清理值可以是:1.23,1.2,4.0...(浮点数)
当需要从DecimalField获取字符串值时,可以使用选项"format_number" => true
$this->add_field("weight", new DecimalField([
"label" => "Weight in kg",
"max_digits" => 6,
"decimal_places" => 3,
"format_number" => true,
]));
此类字段的清理值可以是:"1.230","1.200","4.000"...(字符串)
安装
只需使用Composer即可
cd path/to/your/atk14/project/
composer require atk14/decimal-field
可选地将DecimalField文件符号链接到您的项目中
ln -s ../../vendor/atk14/decimal-field/src/app/fields/decimal_field.php app/fields/decimal_field.php
测试
composer update --dev
cd test
../vendor/bin/run_unit_tests
许可证
DecimalField是免费软件,根据MIT许可证条款分发[MIT许可证]