adt / nette-forms-currency
v1.4.1
2023-05-28 04:39 UTC
Requires
- nette/http: ^2.4 | ^3.0
- nette/utils: ^2.4 | ^3.0 | ^4.0
README
Nette 组件,用于创建货币输入。
安装
使用 Composer 安装货币输入库
composer require adt/nette-forms-currency
并在 bootstrap.php
中注册方法扩展。
\ADT\Forms\Controls\CurrencyInput::register();
这允许你在 Nette\Forms\Form
或 Nette\Forms\Container
类上调用 addCurrency
方法。
对于实时格式化功能,需要创建自定义的 js。
您可以使用下面的示例。安装并链接以下库
nette.ajax.js
autoNumeric
在货币输入上初始化 autoNumeric
$(function () { $.nette.ext('live').after(function ($element) { $element.find('.js-nette-forms-currency').each(function () { new AutoNumeric(this, JSON.parse(this.dataset.options)); }); }); })
用法
非常简单
$form->addCurrency('currency', 'label', \ADT\Forms\Controls\CurrencyInput::CURRENCY_CZK); $form->onSuccess[] = function ($form) { $form['currency']->getValue(); // returns eg. from "100 000 000,56 kč" => "100000000.56" };
并在 latte 中
{input currency}
要在 IDE 中开启自动完成功能,请将 @method CurrencyInput addCurrency($name, $label = null, $currency = null, $language = null)
添加到您的基表单。