Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
edc00e5
BaseControl: added setFixedValue() for a value the user cannot change
dg Oct 28, 2026
4e77cac
opened 4.0-dev
dg Nov 25, 2025
71d65ed
requires PHP 8.4
dg Nov 6, 2026
0ea7d9e
used PHP 8.4 features
dg Nov 6, 2026
cedd3bb
composer: increased dependencies versions
dg Jun 24, 2026
97d1d09
Latte: removed BC alias for the removed formsStack provider
dg Jun 28, 2026
459656a
removed compatibility for old class names
dg Dec 19, 2022
5fb35b6
removed deprecated CsrfProtection control and related code
dg Feb 10, 2026
4e56bba
InputNode, LabelNode: deprecate missing comma before arguments
dg Jun 29, 2026
c3ec669
added type hints (BC break)
dg Jun 25, 2026
e80edbc
Container: only Control/Container can be added to form (BC break)
dg Sep 12, 2021
15fd6af
Container::getControls() returns non-repeatable generator (BC break)
dg May 26, 2026
a1df706
BaseControl::$disabled is bool, added $disabledChoices
dg Mar 31, 2025
0efcd08
Latte: {formContext}, {formContainer}, {formPrint} & {formClassPrint)…
dg Jun 24, 2026
dd0aeb8
netteForms: removed distribution files (BC break)
dg Aug 5, 2024
72caaff
netteForms: restructured package, includes UMD and ESM (BC break)
dg Aug 5, 2024
8e7f338
fixed PHPStan errors: setValue() accepts mixed, simplified Container:…
dg Jul 2, 2026
cb27f18
Form, Container: submitted data are accessed layer by layer via getSu…
dg Jul 2, 2026
18e2a9b
deprecated Form::getHttpData(), BaseControl::getHttpData() and Helper…
dg Jul 4, 2026
308328f
added Repeater: container with dynamically repeating items
dg Jul 7, 2026
b407d92
Latte: added {repeater}, n:repeater-item, n:repeater-add & n:repeater…
dg Jul 11, 2026
b2ae7aa
netteForms: added repeater support
dg Jul 16, 2026
375cce7
added Repeater example
dg Jul 19, 2026
ed8a92b
Form: initialize() removed, the HTTP request resolves lazily per inst…
dg Jul 23, 2026
7517dfc
Form: submission detection redesigned around SubmissionSource objects
dg Jul 23, 2026
21208b2
Control: interface extended to the contract required by the framework…
dg Jul 27, 2026
0283f5a
added Nette\Forms\Validation: configurable validator objects with sta…
dg Aug 12, 2026
2fb7558
Rules: single evaluation point, rule predicates, filters became disti…
dg Aug 17, 2026
8984130
validation message rendering extracted into MessageFormatter; Validat…
dg Aug 17, 2026
a3fd326
addRule() and conditions accept validator objects; string operations …
dg Aug 22, 2026
766dd57
validation HTML attributes are declared by validators and filtered by…
dg Aug 27, 2026
4fcf6b1
message-only keys resolved lazily via Message; repeater counts and po…
dg Sep 1, 2026
eae237a
ClientRuleExporter: static callable written as Class::method(...) is …
dg Sep 8, 2026
8662974
addRule() and conditions verify the argument of string operations eag…
dg Sep 13, 2026
9c54682
added ItemCountValidator: length rules on multi-value controls count …
dg Sep 19, 2026
735feb5
added validator objects example with translations and plurals
dg Sep 19, 2026
9e80d6a
added addUrl() and addPhone(); Float rule on a text input adds inputm…
dg Oct 2, 2026
a42b14e
TextInput: added setSuggestions() rendering a <datalist>
dg Oct 5, 2026
82f06ee
TextBase: the maxlength attribute is enforced on the server
dg Oct 11, 2026
90a9921
DateTimeControl: Equal compares dates and times in the precision of t…
dg Oct 28, 2026
c928efb
Latte: label or control rendered as a string fails with a clear excep…
dg Oct 28, 2026
e8ef6c3
Rules: identical rule replaces the existing one (BC break) [Closes #251]
dg Oct 28, 2026
f3dfaae
netteForms: removed webalize() (BC break)
dg Oct 28, 2026
d1536e4
fix(types): disambiguate array return types in form containers
Nov 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.3', '8.4', '8.5', '8.6']
php: ['8.4', '8.5', '8.6']

fail-fast: false

Expand Down Expand Up @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: 8.4
coverage: none

- run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable
Expand All @@ -49,7 +49,7 @@ jobs:
- uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: 8.4
coverage: pcov

- run: composer install --no-progress --prefer-dist
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ is extended at release time from the git history.
Nette Forms (since 2004) creates, validates, and processes web forms with **both**
server-side (PHP) and client-side (`netteForms.ts`) validation kept in sync.

- **PHP Version**: 8.3 - 8.6
- **PHP Version**: 8.4 - 8.6
- **Package**: `nette/forms`
- **Dependencies**: nette/component-model, nette/http, nette/utils; Latte 3.1.5+.

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
}
],
"require": {
"php": "8.3 - 8.6",
"nette/component-model": "^3.2 || ^4.0",
"php": "8.4 - 8.6",
"nette/component-model": "^4.0",
"nette/http": "^3.4",
"nette/utils": "^4.1"
},
Expand Down Expand Up @@ -45,7 +45,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.3-dev"
"dev-master": "4.0-dev"
}
},
"config": {
Expand Down
5 changes: 3 additions & 2 deletions docs/internals/client-side.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The TypeScript sources in `src/assets/` re-implement the server's rule evaluatio
in the browser. `formValidator.ts` is the engine (`FormValidator` class:
evaluation, toggles, form wiring), `validators.ts` holds the rule twins
(`Validators` class, one method per op), `index.umd.ts` glues them into the
exported `Nette` object (plus `version` and `webalize`). The Rollup build's
exported `Nette` object (plus `version`). The Rollup build's
`fix()` plugin rewrites the UMD banner so the built file **auto-runs
`initOnLoad()`** unless the page pre-sets `Nette = {noInit: true}`.

Expand Down Expand Up @@ -37,7 +37,8 @@ rules with a `{value}` **ref object**; normalizing validators (`url`, `integer`,

## Form wiring (`initForm`)

Forms without any `data-nette-rules` element are left alone. Otherwise the
Forms without any `data-nette-rules` element are left alone, unless they contain
a repeater (whose validated fields may exist only in its `<template>`). Otherwise the
engine computes initial toggles and — unless the form already had `novalidate` —
sets `form.noValidate = true` (taking over from HTML5) and installs a `submit`
handler that cancels submission on failure. `validateForm()` first fails on any
Expand Down
6 changes: 6 additions & 0 deletions docs/internals/controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ are still client-exportable**; once a non-exportable non-branch rule (a filter)
precedes it, the attribute shortcut is disabled, consistent with the export
`break` (the browser must not hard-enforce a limit the filter may change).

The control's own `maxlength` attribute (`setMaxLength()`, the `$maxLength`
factory parameter) is also checked by `TextBase::validate()` against `$rawValue`,
after the rules and only when they passed, so a forged request cannot bypass it.
It is no rule, so it exports nothing to the client, where the attribute itself
already limits the input.

## UploadControl: value comes only from HTTP

`setValue()` is a **no-op** — uploads cannot be defaulted; `getValue()` returns
Expand Down
5 changes: 3 additions & 2 deletions docs/internals/rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ new rendering work goes through Latte.
`Bridges/FormsLatte/Runtime` keeps three **parallel** stacks: `$stack` (the current
form/container scope), `$detachedIds` (the detached form id per stack level,
`null` when not detached) and `$formBindings` (whether the level is bound to the
template's `$form` variable; `{formContainer}` is not). `begin()` pushes and, for a
template's `$form` variable; `{formContainer}` and repeater items are not). `begin()` pushes and, for a
`Form`, fires the render events **and resets every control's `rendered` option** —
`renderFormEnd` (and the default renderer's `renderEnd`) rely on that flag to emit
not-yet-rendered hidden fields before `</form>`; `end()` pops all three and returns
not-yet-rendered hidden fields (and the `<datalist>` of every rendered input with
suggestions) before `</form>`; `end()` pops all three and returns
the nearest remaining level bound to `$form`, which the compiled `{/form}` assigns
back to `$form` (at the top level `$form` keeps the closed form). `get()` resolves an element from the
current scope and —
Expand Down
14 changes: 11 additions & 3 deletions docs/internals/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ The densest part of the package, and the one with the sharpest traps.
`op` field — the op string *is* the validator, mapped to a built-in via
`getCallback()` (`':email'` → `[Validator::class, 'validateEmail']`).

- `addRule`: a `Filled` rule goes to `$required`, everything else to `$rules[]`;
- `addRule`: a `Filled` rule goes to `$required`, everything else to `$rules[]`,
where a rule with an identical validator and argument replaces the existing one
in place (so a custom message overrides the built-in rule of `addEmail()` etc.);
`Valid` is rejected by both `addRule` and `addCondition` — only `addConditionOn`
accepts it.
- `addCondition` turns a bool argument into `:static`; `addConditionOn` creates a
Expand Down Expand Up @@ -73,12 +75,18 @@ stable message id; the op string is the only key.

## DateTimeControl is special-cased across the pipeline

Three distant sites test `instanceof DateTimeControl` explicitly and will break
Four distant sites test `instanceof DateTimeControl` explicitly and will break
together in a refactor:

- `Validation\Operations::toValidator()` maps no `Equal`/`Min`/`Max`/`Range` on it
to a validator object, so these run through the classic validators below.
- `Validator::validateRange()` bypasses `Validators::isInRange` and delegates to
`$control->validateMinMax()` — which for a time-only control **wraps around
midnight** when min > max (22:00–02:00 is a valid range).
midnight** when min > max (22:00–02:00 is a valid range). Likewise
`Validator::validateEqual()` delegates to `$control->validateEqual()`; both
normalize the expected values to the control's type, so a time compares by the
time of day and a date ignores the time part, the same as the client compares
the values exported in the input's format.
- `Validator::formatMessage()` renders rule args via `formatLocaleText()`
(`IntlDateFormatter`, needs ext-intl) instead of string interpolation.
- `Helpers::exportArgument()` serializes args for the client via
Expand Down
6 changes: 3 additions & 3 deletions dresscode.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ overrides:
use:
- compilerOptimizations
- deprecations
- # the BC branch of the deprecated addProtection() and its message
paths: [src/Forms/Form.php, src/Forms/Validator.php]
upgrading: {declarations: {deprecatedClass: keep}}
- # the deprecated getHttpData() keeps working through the deprecated extractHttpData()
paths: [src/Forms/Form.php]
upgrading: {declarations: {deprecatedMember: keep}}
- # Form::URL is established public API
paths: [src/Forms/Form.php]
naming: {constant: keep}
Expand Down
10 changes: 5 additions & 5 deletions examples/custom-control.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct($label = null)
}


public function setValue($value)
public function setValue(mixed $value): static
{
if ($value === null) {
$this->day = $this->month = $this->year = '';
Expand Down Expand Up @@ -57,16 +57,16 @@ public function isFilled(): bool

public function loadHttpData(): void
{
$this->day = $this->getHttpData(Form::DataLine, '[day]');
$this->month = $this->getHttpData(Form::DataLine, '[month]');
$this->year = $this->getHttpData(Form::DataLine, '[year]');
$this->day = $this->getSubmittedValue(Form::DataLine, 'day') ?? '';
$this->month = $this->getSubmittedValue(Form::DataLine, 'month') ?? '';
$this->year = $this->getSubmittedValue(Form::DataLine, 'year') ?? '';
}


/**
* Generates control's HTML element.
*/
public function getControl()
public function getControl(): Html|string
{
$name = $this->getHtmlName();
return Html::el('input', [
Expand Down
79 changes: 79 additions & 0 deletions examples/repeater-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php declare(strict_types=1);

/**
* Example: Form with Repeater (dynamic containers)
*/

if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}

use Nette\Forms\{Container, Form};

Tracy\Debugger::enable();


$form = new Form;

// Add repeater for persons
$persons = $form->addRepeater('persons', function (Container $person) {
$person->addText('firstname', 'Jméno:')
->setRequired();

$person->addText('surname', 'Příjmení:')
->setRequired();

// Nested repeater for emails
$person->addRepeater('emails', function (Container $email) {
$email->addEmail('email', 'Email:')
->setRequired();
})->setBounds(min: 1, max: 3);
});

$persons->setBounds(min: 1, max: 5, default: 2);

// Customize the client-side buttons (optional)
$persons->getAddButtonPrototype()
->setText('Přidat osobu')
->class('btn btn-success');

$persons->getRemoveButtonPrototype()
->setText('Odebrat')
->class('btn btn-danger');

$form->addSubmit('submit', 'Odeslat');


$form->setDefaults([
'persons' => [
[
'firstname' => 'Jan',
'surname' => 'Novák',
'emails' => [
['email' => 'jan@example.com'],
['email' => 'jan.novak@example.com'],
],
],
[
'firstname' => 'Marie',
'surname' => 'Nováková',
'emails' => [
['email' => 'marie@example.com'],
],
],
],
]);


if ($form->isSuccess()) {
echo '<h2>Odeslaná data:</h2>';
Tracy\Dumper::dump($form->getValues());
exit;
}


$latte = new Latte\Engine;
$latte->addExtension(new Nette\Bridges\FormsLatte\FormsExtension);
$latte->setCacheDirectory(__DIR__ . '/temp');

$latte->render(__DIR__ . '/repeater-template.latte', ['form' => $form]);
58 changes: 58 additions & 0 deletions examples/repeater-table.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Repeater Example - Table Rows</title>
<style>
body { font-family: sans-serif; margin: 2em; }
table { border-collapse: collapse; min-width: 700px; }
th, td { border: 1px solid #dee2e6; padding: 0.5em 0.75em; text-align: left; }
thead { background: #f8f9fa; }
input { padding: 0.4em; border: 1px solid #ced4da; border-radius: 3px; width: 95%; box-sizing: border-box; }
td:nth-child(2) input, td:nth-child(3) input { width: 6em; }
.btn {
padding: 0.4em 0.9em;
margin: 0.25em 0;
cursor: pointer;
border: none;
border-radius: 3px;
}
.btn-success { background: #28a745; color: white; }
.btn-danger { background: #dc3545; color: white; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
</style>
<script src="../src/assets/dist/nette-forms.umd.js"></script>
</head>
<body>
<h1>Faktura - položky jako řádky tabulky</h1>

{form $form}
<ul class=error n:ifcontent>
<li n:foreach="$form->getOwnErrors() as $error">{$error}</li>
</ul>

<table>
<thead>
<tr>
<th>Popis</th>
<th>Množství</th>
<th>Cena/ks</th>
<th></th>
</tr>
</thead>
{repeater items}
<td>{input description}</td>
<td>{input quantity}</td>
<td>{input unitPrice}</td>
<td><button n:repeater-remove class="btn btn-danger">×</button></td>
{/repeater}
</table>

<button n:repeater-add="items">+ Přidat řádek</button>

<div style="margin-top: 1.5em;">
{input submit}
</div>
{/form}
</body>
</html>
54 changes: 54 additions & 0 deletions examples/repeater-table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php declare(strict_types=1);

/**
* Example: Repeater rendered as table rows (invoice items)
*/

if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}

use Nette\Forms\{Container, Form};

Tracy\Debugger::enable();


$form = new Form;

$items = $form->addRepeater('items', function (Container $item) {
$item->addText('description', 'Popis:')
->setRequired();

$item->addInteger('quantity', 'Množství:')
->setDefaultValue(1)
->addRule(Form::Min, 'Množství musí být alespoň %d.', 1);

$item->addFloat('unitPrice', 'Cena/ks:')
->setRequired();
});

$items->setBounds(min: 1, max: 10, default: 3);

// the repeater renders as table rows
$items->getContainerPrototype()->setName('tbody');
$items->getItemPrototype()->setName('tr');

$items->getAddButtonPrototype()
->setText('+ Přidat řádek')
->class('btn btn-success');

$form->addSubmit('submit', 'Uložit fakturu');


if ($form->isSuccess()) {
echo '<h2>Odeslaná data:</h2>';
Tracy\Dumper::dump($form->getValues());
exit;
}


$latte = new Latte\Engine;
$latte->addExtension(new Nette\Bridges\FormsLatte\FormsExtension);
$latte->setCacheDirectory(__DIR__ . '/temp');

$latte->render(__DIR__ . '/repeater-table.latte', ['form' => $form]);
Loading