Skip to content

Commit

Permalink
better wording [Closes #1038][Closes #1040][Closes #1026][Closes #1025][
Browse files Browse the repository at this point in the history
Closes #1019][Closes #1016][Closes #1015]
  • Loading branch information
mildabre authored and dg committed Oct 23, 2024
1 parent 703e01f commit a063d62
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions application/cs/components.texy
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Odkaz, který zavolá signál, vytvoříme obvyklým způsobem, tedy v šabloně
<a n:href="click! $x, $y">click here</a>
```

Signál se vždy volá na aktuálním presenteru a view, tudíž není možné jej vyvolat na jiném presenteru nebo view.
Signál se vždy volá na aktuálním presenteru a action, není možné jej vyvolat na jiném presenteru nebo jiné action.

Signál tedy způsobí znovunačtení stránky úplně stejně jako při původním požadavku, jen navíc zavolá obslužnou metodu signálu s příslušnými parametry. Pokud metoda neexistuje, vyhodí se výjimka [api:Nette\Application\UI\BadSignalException], která se uživateli zobrazí jako chybová stránka 403 Forbidden.

Expand Down Expand Up @@ -452,7 +452,7 @@ class PaginatingControl extends Control
}
```

Opačný proces, tedy sesbírání hodnot z persistentních properites, má na starosti metoda `saveState()`.
Opačný proces, tedy sesbírání hodnot z persistentních properties, má na starosti metoda `saveState()`.


Signály do hloubky
Expand All @@ -466,7 +466,7 @@ Signál může přijímat jakákoliv komponenta, presenter nebo objekt, který i

Mezi hlavní příjemce signálů budou patřit `Presentery` a vizuální komponenty dědící od `Control`. Signál má sloužit jako znamení pro objekt, že má něco udělat – anketa si má započítat hlas od uživatele, blok s novinkami se má rozbalit a zobrazit dvakrát tolik novinek, formulář byl odeslán a má zpracovat data a podobně.

URL pro signál vytváříme pomocí metody [Component::link() |api:Nette\Application\UI\Component::link()]. Jako parametr `$destination` předáme řetězec `{signal}!` a jako `$args` pole argumentů, které chceme signálu předat. Signál se vždy volá na aktuální view s aktuálními parametry, parametry signálu se jen přidají. Navíc se přidává hned na začátku **parametr `?do`, který určuje signál**.
URL pro signál vytváříme pomocí metody [Component::link() |api:Nette\Application\UI\Component::link()]. Jako parametr `$destination` předáme řetězec `{signal}!` a jako `$args` pole argumentů, které chceme signálu předat. Signál se vždy volá na aktuálním presenteru a action s aktuálními parametry, parametry signálu se jen přidají. Navíc se přidává hned na začátku **parametr `?do`, který určuje signál**.

Jeho formát je buď `{signal}`, nebo `{signalReceiver}-{signal}`. `{signalReceiver}` je název komponenty v presenteru. Proto nemůže být v názvu komponenty pomlčka – používá se k oddělení názvu komponenty a signálu, je ovšem možné takto zanořit několik komponent.

Expand Down
6 changes: 3 additions & 3 deletions application/en/components.texy
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ The link that calls the signal is created in the usual way, i.e. in the template
<a n:href="click! $x, $y">click here</a>
```

The signal is always called on the current presenter and view, so it is not possible to link to signal in different presenter / action.
The signal is always called on the current presenter and action, it cannot be called on another presenter or action.

Thus, the signal causes the page to be reloaded in exactly the same way as in the original request, only in addition it calls the signal handling method with the appropriate parameters. If the method does not exist, exception [api:Nette\Application\UI\BadSignalException] is thrown, which is displayed to the user as error page 403 Forbidden.

Expand Down Expand Up @@ -452,7 +452,7 @@ class PaginatingControl extends Control
}
```

The opposite process, that is, collecting values from persistent properites, is handled by the `saveState()` method.
The opposite process, that is, collecting values from persistent properties, is handled by the `saveState()` method.


Signals in Depth
Expand All @@ -466,7 +466,7 @@ Signal can be received by any component, presenter of object which implements in

The main receivers of signals are `Presenters` and visual components extending `Control`. A signal is a sign for an object that it has to do something - poll counts in a vote from user, box with news has to unfold, form was sent and has to process data and so on.

The URL for the signal is created using the method [Component::link() |api:Nette\Application\UI\Component::link()]. As parameter `$destination` we pass string `{signal}!` and as `$args` an array of arguments which we want to pass to the signal handler. Signal parameters are attached to the URL of the current presenter/view. **The parameter `?do` in the URL determines the signal called.**
The URL for the signal is created using the [Component::link() |api:Nette\Application\UI\Component::link()] method. We pass the string `{signal}!` as the `$destination` parameter and the array of arguments we want to pass to the signal as `$args`. The signal is always called on the current presenter and action with the current parameters, the signal parameters are just added. In addition, the **parameter `?do`, which specifies the signal** is added right at the beginning.

Its format is `{signal}` or `{signalReceiver}-{signal}`. `{signalReceiver}` is the name of the component in the presenter. This is why hyphen (inaccurately dash) can't be present in the name of components - it is used to divide the name of the component and signal, but it's possible to compose several components.

Expand Down
14 changes: 7 additions & 7 deletions forms/cs/validation.texy
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ $form->addText(/* ... */)
V Nette lze velmi snadno reagovat na splnění či nesplnění podmínky i na straně JavaScriptu pomocí metody `toggle()`, viz [#dynamický JavaScript].


Reference mezi prvky
====================
Reference na jiný prvek
=======================

Jako argument pravidla či podmínky lze uvádět referenci na jiný prvek. Takto lze např. dynamicky validovat, že prvek `text` má tolik znaků, jako je hodnota prvku `length`:
Jako argument pravidla či podmínky lze předat i jiný prvek formuláře. Pravidlo potom použije hodnotu vloženou později uživatelem v prohlížeči. Takto lze např. dynamicky validovat, že prvek `password` obsahuje stejný řetězec jako prvek `password_confirm`:

```php
$form->addInteger('length');
$form->addText('text')
->addRule($form::LENGTH, null, $form['length']);
$form->addPassword('password', 'Heslo');
$form->addPassword('password_confirm', 'Potvrďte heslo')
->addRule($form::EQUAL, 'Zadaná hesla se neshodují', $form['password']);
```


Expand All @@ -172,7 +172,7 @@ Vlastní pravidla a podmínky

Občas se dostaneme do situace, kdy nám vestavěná validační pravidla v Nette nestačí a potřebujeme data od uživatele validovat po svém. V Nette je to velmi jednoduché!

Metodám `addRule()` či `addCondition()` lze první parametr předat libovolný callback. Ten přijímá jako první parametr samotný prvek a vrací boolean hodnotu určující, zda validace proběhla v pořádku. Při přidávání pravidla pomocí `addRule()` je možné zadat i další argumenty, ty jsou pak předány jako druhý parametr.
Metodám `addRule()` či `addCondition()` lze jako první parametr předat libovolný callback. Ten přijímá jako první parametr samotný prvek a vrací boolean hodnotu určující, zda validace proběhla v pořádku. Při přidávání pravidla pomocí `addRule()` je možné zadat i další argumenty, ty jsou pak předány jako druhý parametr.

Vlastní sadu validátorů tak můžeme vytvořit jako třídu se statickými metodami:

Expand Down
12 changes: 6 additions & 6 deletions forms/en/validation.texy
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ $form->addText(/* ... */)
In Nette, it is very easy to react to the fulfillment or not of a condition on the JavaScript side using the `toggle()` method, see [#Dynamic JavaScript].


References Between Controls
===========================
Reference to Another Element
============================

The rule or condition argument can be a reference to another element. For example, you can dynamically validate that the `text` has as many characters as the value of the `length` field is:
As an argument for a rule or condition, you can also pass another form element. The rule will then use the value entered later by the user in the browser. This can be used, for example, to dynamically validate that the `password` element contains the same string as the `password_confirm` element:

```php
$form->addInteger('length');
$form->addText('text')
->addRule($form::LENGTH, null, $form['length']);
$form->addPassword('password', 'Password');
$form->addPassword('password_confirm', 'Confirm Password')
->addRule($form::EQUAL, 'The passwords do not match', $form['password']);
```


Expand Down

0 comments on commit a063d62

Please sign in to comment.