diff --git a/forms/cs/validation.texy b/forms/cs/validation.texy index 919afc032c..b8ef19407e 100644 --- a/forms/cs/validation.texy +++ b/forms/cs/validation.texy @@ -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']); ``` diff --git a/forms/en/validation.texy b/forms/en/validation.texy index edc865c357..215f7c21e8 100644 --- a/forms/en/validation.texy +++ b/forms/en/validation.texy @@ -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']); ```