nepada / birth-number-input
Czech birth number form input for Nette forms.
Installs: 1 694
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=8.1.0 <8.5
- nepada/birth-number: ^1.0@dev
- nette/forms: ^3.1@dev
- nette/utils: ^3.2@dev || ^4.0@dev
Requires (Dev)
- composer-runtime-api: ^2.0
- composer/semver: 3.4.3
- mockery/mockery: 1.6.12
- nepada/coding-standard: 7.14.1
- nepada/phpstan-nette-tester: 1.2.1
- nette/bootstrap: >=3.1@dev
- nette/component-model: >=3.0.2
- nette/di: ^3.0.6@dev
- nette/http: >=3.1.0@dev
- nette/neon: ^3.3.4@dev
- nette/robot-loader: *@dev
- nette/tester: 2.5.4
- php-parallel-lint/php-parallel-lint: 1.4.0
- phpstan/phpstan: 1.12.7
- phpstan/phpstan-mockery: 1.1.3
- phpstan/phpstan-nette: 1.3.8
- phpstan/phpstan-strict-rules: 1.6.1
- shipmonk/phpstan-rules: 3.2.1
- spaze/phpstan-disallowed-calls: 3.5.1
This package is auto-updated.
Last update: 2024-10-28 07:17:30 UTC
README
Installation
Via Composer:
$ composer require nepada/birth-number-input
Option A: install form container extension method via DI extension
extensions: - Nepada\Bridges\BirthNumberInputDI\BirthNumberInputExtension
It will register extension method addBirthNumber($name, $label = null): BirthNumberInput
to Nette\Forms\Container
.
Option B: use trait in your base form/container class
You can also use BirthNumberInputMixin
trait in your base form/container class to add method addBirthNumber($name, $label = null): BirthNumberInput
.
Example:
trait FormControls { use Nepada\Bridges\BirthNumberInputForms\BirthNumberInputMixin; public function addContainer($name) { $control = new Container; $control->setCurrentGroup($this->getCurrentGroup()); if ($this->currentGroup !== null) { $this->currentGroup->add($control); } return $this[$name] = $control; } } class Container extends Nette\Forms\Container { use FormControls; } class Form extends Nette\Forms\Form { use FormControls; }
Usage
BirthNumberInput
is form control that uses birth number value object to represent its value (see nepada/birth-number for further details).
It automatically validates the user input and getValue()
method always returns BirthNumber
instance, or null
if the input is not filled.
$birthNumberInput = $form->addBirthNumber('birthNumber'); $birthNumberInput->setValue('invalid'); // \InvalidArgumentException is thrown $birthNumberInput->setValue('000101 / 0009'); // the value is internally converted to BirthNumber value object $birthNumberInput->getValue(); // BirthNumber instance for 000101/0009
Client side validation
Using precompiled bundle
Using precompiled bundles is the quick'n'dirty way of getting client side validation to work.
<script src="https://unpkg.com/nette-forms@%5E3.0/src/assets/netteForms.min.js"></script> <script src="https://unpkg.com/@nepada/birth-number-input@%5E1.0/dist/birth-number-input.min.js"></script>
Building your own bundle
It is highly recommended to install the client side package via nmp and compile your own bundle.
Here is an example script for initialization of birth number input and Nette forms.
import Nette from 'nette-forms'; import initializeBirthNumberInput from '@nepada/birth-number-input'; initializeBirthNumberInput(Nette); Nette.initOnLoad();