Statistics
2808
2
2
210d
Badges
Tags
forms
Dependencies

Downloads this Month Latest Stable Version

Disclaimer

As support for multi-control inputs in Nette is not really rich, this component have some limitations:

  • There is hardcoded rendering for Bootstrap3, you are not force to use it, but the structure of elements and classes attached to it are hardcoded. If you want to use your own "skin" you can use:
  • Methods getAmountControlPrototype() and getCurrencyControlPrototype() to reach input and select elements.
  • CSS classes moneyInputControlContainer, moneyInputAmountContainer and moneyInputCurrencyContainer to adjust placement of inputs.
  • There is also limitation in addRule() there is support only for:
  • Form::FILLED and Form::REQUIRED - You can also use setRequired().
  • and Form::RANGE - But there is no support for currencies. Its recommended to use it for positive / negative limitation only.

Installation

Composer:

composer require achse/nette-money-input

Javascript Dependencies

npm install jquery

If you are using webloader:

webloader:
	js:
		default:
			files:
				- %wwwDir%/../vendor/achse/nette-money-input/assets/moneyInput.js

Usage

Without currency information

You need to implement your ICurrencyFinder to transform Currency-Code string to object.

class CurrencyFinder extends Object implements ICurrencyFinder
{
	private $currencyRepository;

	public function __construct(EntityManager $entityManager)
	{
		$this->currencyRepository = $entityManager->getRepository(Currency::class);
	}

	/**
	 * @inheritdoc
	 */
	public function findByCode($code)
	{
		/** @var Currency $currency */
		$currency = $this->currencyRepository->findOneBy(['code' => $code]);
		if ($currency === NULL) {
			throw new CurrencyNotFoundException("Currency '{$code}' not found.");
		}

		return $currency;
	}
}

And then define addMoney method in you whatever Form class / trait.

/**
 * @param string $name
 * @param string|NULL $label
 * @param array $currencyCodeOptions
 * @param ICurrencyFinder $currencyFinder
 * @return MoneyInput
 */
public function addMoney($name, $label = NULL, array $currencyCodeOptions, ICurrencyFinder $currencyFinder)
{
	$input = new MoneyInput($label, MoneyInput::AMOUNT_LENGTH_LIMIT, $currencyCodeOptions, $currencyFinder);

	return $this[$name] = $input;
}
  • 2.1.1 2.1.1

  • 2.1 Allow to install Nette 2.4

  • 2.0.0 Validation for empty string enhanced

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com