Skip to content

AppsDevTeam/nette-forms-currency

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 

Repository files navigation

Currency input for Nette Forms

Nette component for creating currency input.

Installation

Install currency input library via composer:

composer require adt/nette-forms-currency

and register method extension in bootstrap.php:

\ADT\Forms\Controls\CurrencyInput::register();

This allows you to call the method addCurrency on class Nette\Forms\Form or Nette\Forms\Container.

For live formatting functionality its necessary to create custom js.
You can use our example bellow. Install and link following libraries:
nette.ajax.js
autoNumeric

Initialize autoNumeric on currency input

$(function () {
	$.nette.ext('live').after(function ($element) {
		$element.find('.js-nette-forms-currency').each(function () {
			new AutoNumeric(this, JSON.parse(this.dataset.options));
		});
	});
})

Usage

It's very simple:

$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" 
};

And in latte:

{input currency}

To turn on autocomplete in IDE, add @method CurrencyInput addCurrency($name, $label = null, $currency = null, $language = null) to your base form.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages