Skip to content

Commit

Permalink
forms: slightly improved HTML attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 5, 2024
1 parent 138fbaf commit 3af79c4
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 158 deletions.
19 changes: 9 additions & 10 deletions forms/bg/rendering.texy
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ $form->addSelect('country', '小褌褉邪薪邪:', $countries);
袗褌褉懈斜褍褌懈 薪邪 HTML .[#toc-html-attributes]
========================================

袦芯卸械褌械 写邪 蟹邪写邪胁邪褌械 胁褋褟泻邪泻胁懈 HTML 邪褌褉懈斜褍褌懈 蟹邪 泻芯薪褌褉芯谢懈褌械 薪邪 褎芯褉屑褍谢褟褉邪, 泻邪褌芯 懈蟹锌芯谢蟹胁邪褌械 `setHtmlAttribute(string $name, $value = true)`:
袟邪 蟹邪写邪胁邪薪械 薪邪 锌褉芯懈蟹胁芯谢薪懈 HTML 邪褌褉懈斜褍褌懈 蟹邪 械谢械屑械薪褌懈褌械 薪邪 褎芯褉屑邪褌邪 懈蟹锌芯谢蟹胁邪泄褌械 屑械褌芯写邪 `setHtmlAttribute(string $name, $value = true)`:

```php
$form->addInteger('number', 'Number:')
Expand All @@ -452,20 +452,23 @@ $form->addSelect('rank', 'Order:', ['price', 'name'])
->setHtmlAttribute('onchange', 'submit()'); // 懈蟹胁懈泻胁邪薪械 薪邪 JS 褎褍薪泻褑懈褟褌邪 submit() 锌褉懈 锌褉芯屑褟薪邪


//锌褉懈谢邪谐邪 褋械 蟹邪 <form>
// 袟邪 蟹邪写邪胁邪薪械 薪邪 邪褌褉懈斜褍褌懈 薪邪 褋邪屑懈褟 <form>
$form->setHtmlAttribute('id', 'myForm');
```

袟邪写邪胁邪薪械 薪邪 褌懈锌邪 薪邪 胁谢懈蟹邪薪械:
袩芯褋芯褔胁邪薪械 薪邪 褌懈锌邪 薪邪 械谢械屑械薪褌邪:

```php
$form->addText('tel', '袙邪褕 褌械谢械褎芯薪:')
->setHtmlType('tel')
->setHtmlAttribute('placeholder', '袩芯卸邪谢褍泄褋褌邪, 蟹邪锌芯谢薪懈褌械 胁邪褕 褌械谢械褎芯薪');
```

袦芯卸械屑 写邪 蟹邪写邪写械屑 HTML 邪褌褉懈斜褍褌 蟹邪 芯褌写械谢薪懈褌械 械谢械屑械薪褌懈 胁 褋锌懈褋褗褑懈褌械 褋 褉邪写懈芯泻谢懈锌芯胁械 懈谢懈 泻胁邪写褉邪褌褔械褌邪 褋 褉邪蟹谢懈褔薪懈 褋褌芯泄薪芯褋褌懈 蟹邪 胁褋械泻懈 芯褌 褌褟褏.
袨斜褗褉薪械褌械 胁薪懈屑邪薪懈械 薪邪 写胁芯械褌芯褔懈械褌芯 褋谢械写 `style:`, 蟹邪 写邪 褋械 谐邪褉邪薪褌懈褉邪, 褔械 褋褌芯泄薪芯褋褌褌邪 械 懈蟹斜褉邪薪邪 芯褌 泻谢褞褔邪:
.[warning]
袟邪写邪胁邪薪械褌芯 薪邪 褌懈锌邪 懈 写褉褍谐懈褌械 邪褌褉懈斜褍褌懈 褋谢褍卸懈 褋邪屑芯 蟹邪 胁懈蟹褍邪谢薪懈 褑械谢懈. 袩褉芯胁械褉泻邪褌邪 薪邪 泻芯褉械泻褌薪芯褋褌褌邪 薪邪 胁褗胁械写械薪懈褌械 写邪薪薪懈 褌褉褟斜胁邪 写邪 褋械 懈蟹胁褗褉褕懈 薪邪 褋褗褉胁褗褉邪, 泻芯械褌芯 屑芯卸械褌械 写邪 芯褋懈谐褍褉懈褌械 褔褉械蟹 懈蟹斜芯褉 薪邪 锌芯写褏芯写褟褖 [泻芯薪褌褉芯谢 薪邪 褎芯褉屑邪褌邪 | controls] 懈 蟹邪写邪胁邪薪械 薪邪 [锌褉邪胁懈谢邪 蟹邪 胁邪谢懈写懈褉邪薪械 | validation].

袟邪 芯褌写械谢薪懈褌械 械谢械屑械薪褌懈 胁 褋锌懈褋褗褑懈褌械 褋 褉邪写懈芯褋褌邪薪褑懈懈 懈谢懈 泻胁邪写褉邪褌褔械褌邪 屑芯卸械屑 写邪 蟹邪写邪写械屑 HTML 邪褌褉懈斜褍褌 褋 褉邪蟹谢懈褔薪懈 褋褌芯泄薪芯褋褌懈 蟹邪 胁褋械泻懈 芯褌 褌褟褏.
袨斜褗褉薪械褌械 胁薪懈屑邪薪懈械 薪邪 写胁芯械褌芯褔懈械褌芯 褋谢械写 `style:`, 泻芯械褌芯 谐邪褉邪薪褌懈褉邪, 褔械 褋褌芯泄薪芯褋褌褌邪 褋械 懈蟹斜懈褉邪 胁褗蟹 芯褋薪芯胁邪 薪邪 泻谢褞褔邪:

```php
$colors = ['r' => 'red', 'g' => 'green', 'b' => 'blue'];
Expand All @@ -482,10 +485,9 @@ $form->addCheckboxList('colors', '笑胁械褌邪:', $colors)
<label><input type="checkbox" name="colors[]" value="b">blue</label>
```

袙褗锌褉芯褋懈褌械谢薪懈褟褌 蟹薪邪泻 屑芯卸械 写邪 褋械 懈蟹锌芯谢蟹胁邪 蟹邪 斜褍谢械胁 HTML 邪褌褉懈斜褍褌 (泻芯泄褌芯 薪褟屑邪 褋褌芯泄薪芯褋褌, 薪邪锌褉懈屑械褉 `readonly`):
袟邪 蟹邪写邪胁邪薪械 薪邪 斜褍谢械胁懈 邪褌褉懈斜褍褌懈, 泻邪褌芯 薪邪锌褉懈屑械褉 `readonly`, 屑芯卸械屑 写邪 懈蟹锌芯谢蟹胁邪屑械 芯蟹薪邪褔械薪懈械褌芯 褋 胁褗锌褉芯褋懈褌械谢械薪 蟹薪邪泻:

```php
$colors = ['r' => 'red', 'g' => 'green', 'b' => 'blue'];
$form->addCheckboxList('colors', 'Colors:', $colors)
->setHtmlAttribute('readonly?', 'r'); // 懈蟹锌芯谢蟹胁邪泄褌械 屑邪褋懈胁 蟹邪 薪褟泻芯谢泻芯 泻谢褞褔邪, 薪邪锌褉懈屑械褉 ['r', 'g']
```
Expand Down Expand Up @@ -539,9 +541,6 @@ $html->class('distinctive'); // <label class="distinctive">

```php
$input = $form->addCheckbox('send');
echo $input->getControl();
// <label><input type="checkbox" name="send"></label>

$html = $input->getContainerPrototype();
$html->setName('div'); // <div>
$html->class('check'); // <div class="check">
Expand Down
15 changes: 7 additions & 8 deletions forms/cs/rendering.texy
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ Podpora pro Bootstrap
HTML atributy
=============

Formul谩艡ov媒m prvk暖m m暖啪eme nastavovat libovoln茅 HTML atributy pomoc铆 `setHtmlAttribute(string $name, $value = true)`:
Pro nastaven铆 libovoln媒ch HTML atribut暖 formul谩艡ov媒ch prvk暖 pou啪ijeme metodu `setHtmlAttribute(string $name, $value = true)`:

```php
$form->addInteger('number', '膶铆slo:')
Expand All @@ -452,18 +452,21 @@ $form->addSelect('rank', '艠azen铆 dle:', ['ceny', 'n谩zvu'])
->setHtmlAttribute('onchange', 'submit()'); // p艡i zm臎n臎 odeslat


// chceme-li to sam茅 ud臎lat pro <form>
// Pro nastaven铆 atribut暖 samotn茅ho <form>
$form->setHtmlAttribute('id', 'myForm');
```

Nastaven铆 typu:
Specifikace typu prvku:

```php
$form->addText('tel', 'V谩拧 telefon:')
->setHtmlType('tel')
->setHtmlAttribute('placeholder', 'napi拧te telefon');
```

.[warning]
Nastaven铆 typu a dal拧铆ch atribut暖 slou啪铆 jen pro vizu谩ln铆 煤膷ely. Ov臎艡en铆 spr谩vnosti vstup暖 mus铆 prob铆hat na serveru, co啪 zaj铆st铆te volbou vhodn茅ho [formul谩艡ov茅ho prvku|controls] a uveden铆m [valida膷n铆ch pravidel|validation].

Jednotliv媒m polo啪k谩m v radio nebo checkbox listech m暖啪eme nastavit HTML atribut s rozd铆ln媒mi hodnotami pro ka啪dou z nich.
Pov拧imn臎te si dvojte膷ky za `style:`, kter谩 zajist铆 volbu hodnoty podle kl铆膷e:

Expand All @@ -482,10 +485,9 @@ Vyp铆拧e:
<label><input type="checkbox" name="colors[]" value="b">modr谩</label>
```

Pokud jde o logick媒 HTML atribut (kter媒 nem谩 hodnotu, nap艡. `readonly`), m暖啪eme pou啪铆t z谩pis s otazn铆kem:
Pro nastaven铆 logick媒ch atribut暖, jako je `readonly`, m暖啪eme pou啪铆t z谩pis s otazn铆kem:

```php
$colors = ['r' => '膷erven谩', 'g' => 'zelen谩', 'b' => 'modr谩'];
$form->addCheckboxList('colors', 'Barvy:', $colors)
->setHtmlAttribute('readonly?', 'r'); // pro v铆ce kl铆膷u pou啪ijte pole, nap艡. ['r', 'g']
```
Expand Down Expand Up @@ -539,9 +541,6 @@ U prvk暖 Checkbox, CheckboxList a RadioList m暖啪ete ovlivnit p艡edlohu elementu

```php
$input = $form->addCheckbox('send');
echo $input->getControl();
// <label><input type="checkbox" name="send"></label>

$html = $input->getContainerPrototype();
$html->setName('div'); // <div>
$html->class('check'); // <div class="check">
Expand Down
19 changes: 9 additions & 10 deletions forms/de/rendering.texy
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ Sie k枚nnen [Beispiele |https://github.com/nette/forms/tree/master/examples] f眉
HTML-Attribute .[#toc-html-attributes]
======================================

Mit `setHtmlAttribute(string $name, $value = true)` k枚nnen Sie beliebige HTML-Attribute f眉r Formularsteuerelemente festlegen:
Um beliebige HTML-Attribute f眉r Formularelemente zu setzen, verwenden Sie die Methode `setHtmlAttribute(string $name, $value = true)`:

```php
$form->addInteger('number', 'Zahl:')
Expand All @@ -452,20 +452,23 @@ $form->addSelect('rank', 'Sortieren nach:', ['Preis', 'Name'])
->setHtmlAttribute('onchange', 'submit()'); // ruft JS-Funktion submit() bei 脛nderung auf


// Anwendung auf <form>
// Zum Festlegen von Attributen der <form> selbst
$form->setHtmlAttribute('id', 'myForm');
```

Einstellung des Eingabetyps:
Angabe der Art des Elements:

```php
$form->addText('tel', 'Your telephone:')
->setHtmlType('tel')
->setHtmlAttribute('placeholder', 'Please, fill in your telephone');
```

Wir k枚nnen HTML-Attribute f眉r einzelne Elemente in Radio- oder Checkbox-Listen mit unterschiedlichen Werten f眉r jedes dieser Elemente festlegen.
Beachten Sie den Doppelpunkt nach `style:`, um sicherzustellen, dass der Wert nach Schl眉ssel ausgew盲hlt wird:
.[warning]
Das Setzen des Typs und anderer Attribute dient nur der visuellen Darstellung. Die 脺berpr眉fung der Korrektheit der Eingabe muss auf dem Server erfolgen, was Sie durch die Wahl eines geeigneten [Formularsteuerelements | controls] und die Festlegung von [Validierungsregeln | validation] sicherstellen k枚nnen.

F眉r einzelne Elemente in Radio- oder Checkbox-Listen k枚nnen wir ein HTML-Attribut mit unterschiedlichen Werten f眉r jedes dieser Elemente setzen.
Beachten Sie den Doppelpunkt nach `style:`, der sicherstellt, dass der Wert anhand des Schl眉ssels ausgew盲hlt wird:

```php
$colors = ['r' => 'red', 'g' => 'green', 'b' => 'blue'];
Expand All @@ -482,10 +485,9 @@ Renders:
<label><input type="checkbox" name="colors[]" value="b">blue</label>
```

F眉r ein logisches HTML-Attribut (das keinen Wert hat, wie `readonly`) k枚nnen Sie ein Fragezeichen verwenden:
F眉r das Setzen von booleschen Attributen, wie z. B. `readonly`, k枚nnen wir die Notation mit einem Fragezeichen verwenden:

```php
$colors = ['r' => 'red', 'g' => 'green', 'b' => 'blue'];
$form->addCheckboxList('colors', 'Colors:', $colors)
->setHtmlAttribute('readonly?', 'r'); // use array for multiple keys, e.g. ['r', 'g']
```
Expand Down Expand Up @@ -539,9 +541,6 @@ F眉r Checkbox-, CheckboxList- und RadioList-Elemente k枚nnen Sie die Elementvorl

```php
$input = $form->addCheckbox('send');
echo $input->getControl();
// <label><input type="checkbox" name="send"></label>

$html = $input->getContainerPrototype();
$html->setName('div'); // <div>
$html->class('check'); // <div class="check">
Expand Down
19 changes: 9 additions & 10 deletions forms/el/rendering.texy
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ $form->addSelect('country', 'Country:', $countries);
围伪蟻伪魏蟿畏蟻喂蟽蟿喂魏维 HTML .[#toc-html-attributes]
===========================================

螠蟺慰蟻蔚委蟿蔚 谓伪 慰蟻委蟽蔚蟿蔚 慰蟺慰喂伪未萎蟺慰蟿蔚 蠂伪蟻伪魏蟿畏蟻喂蟽蟿喂魏维 HTML 蟽蔚 蟽蟿慰喂蠂蔚委伪 蔚位苇纬蠂慰蠀 蠁蠈蟻渭伪蟼 蠂蟻畏蟽喂渭慰蟺慰喂蠋谓蟿伪蟼 蟿慰 `setHtmlAttribute(string $name, $value = true)`:
螕喂伪 谓伪 慰蟻委蟽蔚蟿蔚 伪蠀胃伪委蟻蔚蟿伪 蠂伪蟻伪魏蟿畏蟻喂蟽蟿喂魏维 HTML 纬喂伪 蟽蟿慰喂蠂蔚委伪 蠁蠈蟻渭伪蟼, 蠂蟻畏蟽喂渭慰蟺慰喂萎蟽蟿蔚 蟿畏 渭苇胃慰未慰 `setHtmlAttribute(string $name, $value = true)`:

```php
$form->addInteger('number', 'Number:')
Expand All @@ -452,20 +452,23 @@ $form->addSelect('rank', 'Order by:', ['price', 'name'])
->setHtmlAttribute('onchange', 'submit()'); // 魏伪位蔚委 蟿畏 蟽蠀谓维蟻蟿畏蟽畏 JS submit() 魏伪蟿维 蟿畏谓 伪位位伪纬萎


// applying on <form>
// 螕喂伪 谓伪 慰蟻委蟽蔚蟿蔚 蟿伪 蠂伪蟻伪魏蟿畏蟻喂蟽蟿喂魏维 蟿慰蠀 委未喂慰蠀 蟿慰蠀 <form>
$form->setHtmlAttribute('id', 'myForm');
```

巍蠉胃渭喂蟽畏 蟿蠉蟺慰蠀 蔚喂蟽蠈未慰蠀:
螝伪胃慰蟻喂蟽渭蠈蟼 蟿慰蠀 蟿蠉蟺慰蠀 蟿慰蠀 蟽蟿慰喂蠂蔚委慰蠀:

```php
$form->addText('tel', 'Your telephone:')
->setHtmlType('tel')
->setHtmlAttribute('placeholder', 'Please, fill in your telephone');
```

螠蟺慰蟻慰蠉渭蔚 谓伪 慰蟻委蟽慰蠀渭蔚 蟿慰 蠂伪蟻伪魏蟿畏蟻喂蟽蟿喂魏蠈 HTML 蟽蔚 渭蔚渭慰谓蠅渭苇谓伪 蟽蟿慰喂蠂蔚委伪 蟽蔚 位委蟽蟿蔚蟼 蟻伪未喂慰蠁蠋谓慰蠀 萎 checkbox 渭蔚 未喂伪蠁慰蟻蔚蟿喂魏苇蟼 蟿喂渭苇蟼 纬喂伪 魏维胃蔚 苇谓伪 伪蟺蠈 伪蠀蟿维.
螤蟻慰蟽苇尉蟿蔚 蟿畏谓 维谓蠅 魏伪喂 魏维蟿蠅 蟿蔚位蔚委伪 渭蔚蟿维 蟿慰 `style:` 纬喂伪 谓伪 未喂伪蟽蠁伪位委蟽蔚蟿蔚 蠈蟿喂 畏 蟿喂渭萎 蔚蟺喂位苇纬蔚蟿伪喂 渭蔚 尾维蟽畏 蟿慰 魏位蔚喂未委:
.[warning]
螣 魏伪胃慰蟻喂蟽渭蠈蟼 蟿慰蠀 蟿蠉蟺慰蠀 魏伪喂 维位位蠅谓 蠂伪蟻伪魏蟿畏蟻喂蟽蟿喂魏蠋谓 蠂蟻畏蟽喂渭蔚蠉蔚喂 渭蠈谓慰 纬喂伪 慰蟺蟿喂魏慰蠉蟼 蟽魏慰蟺慰蠉蟼. 螚 蔚蟺伪位萎胃蔚蠀蟽畏 蟿畏蟼 慰蟻胃蠈蟿畏蟿伪蟼 蟿畏蟼 蔚喂蟽蠈未慰蠀 蟺蟻苇蟺蔚喂 谓伪 纬委谓蔚蟿伪喂 蟽蟿慰 未喂伪魏慰渭喂蟽蟿萎, 魏维蟿喂 蟺慰蠀 渭蟺慰蟻蔚委蟿蔚 谓伪 蔚尉伪蟽蠁伪位委蟽蔚蟿蔚 蔚蟺喂位苇纬慰谓蟿伪蟼 苇谓伪 魏伪蟿维位位畏位慰 [蟽蟿慰喂蠂蔚委慰 蔚位苇纬蠂慰蠀 蠁蠈蟻渭伪蟼 | controls] 魏伪喂 魏伪胃慰蟻委味慰谓蟿伪蟼 [魏伪谓蠈谓蔚蟼 蔚蟺喂魏蠉蟻蠅蟽畏蟼 | validation].

螕喂伪 渭蔚渭慰谓蠅渭苇谓伪 蟽蟿慰喂蠂蔚委伪 蟽蔚 位委蟽蟿蔚蟼 蟻伪未喂慰蠁蠋谓慰蠀 萎 checkbox, 渭蟺慰蟻慰蠉渭蔚 谓伪 慰蟻委蟽慰蠀渭蔚 苇谓伪 蠂伪蟻伪魏蟿畏蟻喂蟽蟿喂魏蠈 HTML 渭蔚 未喂伪蠁慰蟻蔚蟿喂魏苇蟼 蟿喂渭苇蟼 纬喂伪 魏伪胃苇谓伪 伪蟺蠈 伪蠀蟿维.
螤伪蟻伪蟿畏蟻萎蟽蟿蔚 蟿畏谓 维谓蠅 魏伪喂 魏维蟿蠅 蟿蔚位蔚委伪 渭蔚蟿维 蟿慰 `style:`, 畏 慰蟺慰委伪 未喂伪蟽蠁伪位委味蔚喂 蠈蟿喂 畏 蟿喂渭萎 蔚蟺喂位苇纬蔚蟿伪喂 渭蔚 尾维蟽畏 蟿慰 魏位蔚喂未委:

```php
$colors = ['r' => 'red', 'g' => 'green', 'b' => 'blue'];
Expand All @@ -482,10 +485,9 @@ Renders:
<label><input type="checkbox" name="colors[]" value="b">blue</label>
```

螕喂伪 苇谓伪 位慰纬喂魏蠈 蠂伪蟻伪魏蟿畏蟻喂蟽蟿喂魏蠈 HTML (蟿慰 慰蟺慰委慰 未蔚谓 苇蠂蔚喂 蟿喂渭萎, 蠈蟺蠅蟼 蟿慰 `readonly`), 渭蟺慰蟻蔚委蟿蔚 谓伪 蠂蟻畏蟽喂渭慰蟺慰喂萎蟽蔚蟿蔚 苇谓伪 蔚蟻蠅蟿畏渭伪蟿喂魏蠈:
螕喂伪 蟿慰谓 魏伪胃慰蟻喂蟽渭蠈 boolean 蠂伪蟻伪魏蟿畏蟻喂蟽蟿喂魏蠋谓, 蠈蟺蠅蟼 蟿慰 `readonly`, 渭蟺慰蟻慰蠉渭蔚 谓伪 蠂蟻畏蟽喂渭慰蟺慰喂萎蟽慰蠀渭蔚 蟿慰谓 蟽蠀渭尾慰位喂蟽渭蠈 渭蔚 蔚蟻蠅蟿畏渭伪蟿喂魏蠈:

```php
$colors = ['r' => 'red', 'g' => 'green', 'b' => 'blue'];
$form->addCheckboxList('colors', 'Colors:', $colors)
->setHtmlAttribute('readonly?', 'r'); // 蠂蟻萎蟽畏 蟺委谓伪魏伪 纬喂伪 蟺慰位位伪蟺位维 魏位蔚喂未喂维, 蟺.蠂. ['r', 'g']
```
Expand Down Expand Up @@ -539,9 +541,6 @@ $html->class('distinctive'); // <label class="distinctive">

```php
$input = $form->addCheckbox('send');
echo $input->getControl();
// <label><input type="checkbox" name="send"></label>

$html = $input->getContainerPrototype();
$html->setName('div'); // <div>
$html->class('check'); // <div class="check">
Expand Down
19 changes: 9 additions & 10 deletions forms/en/rendering.texy
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ You can find [examples |https://github.com/nette/forms/tree/master/examples] of
HTML Attributes
===============

You can set any HTML attributes to form controls using `setHtmlAttribute(string $name, $value = true)`:
To set arbitrary HTML attributes for form elements, use the method `setHtmlAttribute(string $name, $value = true)`:

```php
$form->addInteger('number', 'Number:')
Expand All @@ -452,20 +452,23 @@ $form->addSelect('rank', 'Order by:', ['price', 'name'])
->setHtmlAttribute('onchange', 'submit()'); // calls JS function submit() on change


// applying on <form>
// To set attributes of the <form> itself
$form->setHtmlAttribute('id', 'myForm');
```

Setting input type:
Specifying the type of element:

```php
$form->addText('tel', 'Your telephone:')
->setHtmlType('tel')
->setHtmlAttribute('placeholder', 'Please, fill in your telephone');
```

We can set HTML attribute to individual items in radio or checkbox lists with different values for each of them.
Note the colon after `style:` to ensure that the value is selected by key:
.[warning]
Setting the type and other attributes serves only for visual purposes. Verification of input correctness must occur on the server, which you can ensure by choosing an appropriate [form control | controls] and specifying [validation rules | validation].

For individual items in radio or checkbox lists, we can set an HTML attribute with different values for each of them.
Notice the colon after `style:`, which ensures the value is selected based on the key:

```php
$colors = ['r' => 'red', 'g' => 'green', 'b' => 'blue'];
Expand All @@ -482,10 +485,9 @@ Renders:
<label><input type="checkbox" name="colors[]" value="b">blue</label>
```

For a logical HTML attribute (which has no value, such as `readonly`), you can use a question mark:
For setting boolean attributes, such as `readonly`, we can use the notation with a question mark:

```php
$colors = ['r' => 'red', 'g' => 'green', 'b' => 'blue'];
$form->addCheckboxList('colors', 'Colors:', $colors)
->setHtmlAttribute('readonly?', 'r'); // use array for multiple keys, e.g. ['r', 'g']
```
Expand Down Expand Up @@ -539,9 +541,6 @@ For Checkbox, CheckboxList and RadioList items you can influence the element tem

```php
$input = $form->addCheckbox('send');
echo $input->getControl();
// <label><input type="checkbox" name="send"></label>

$html = $input->getContainerPrototype();
$html->setName('div'); // <div>
$html->class('check'); // <div class="check">
Expand Down
19 changes: 9 additions & 10 deletions forms/es/rendering.texy
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ Puede encontrar [ejemplos |https://github.com/nette/forms/tree/master/examples]
Atributos HTML .[#toc-html-attributes]
======================================

Puede establecer cualquier atributo HTML a los controles de formulario utilizando `setHtmlAttribute(string $name, $value = true)`:
Para establecer atributos HTML arbitrarios para elementos de formulario, utilice el m茅todo `setHtmlAttribute(string $name, $value = true)`:

```php
$form->addInteger('number', 'N煤mero:')
Expand All @@ -452,20 +452,23 @@ $form->addSelect('range', 'Ordenar por:', ['precio', 'nombre'])
->setHtmlAttribute('onchange', 'submit()'); // llama a la funci贸n JS submit() al cambiar


// aplicando en <form>
// Para establecer atributos del propio <form>
$form->setHtmlAttribute('id', 'myForm');
```

Configuraci贸n del tipo de entrada:
Especificaci贸n del tipo de elemento:

```php
$form->addText('tel', 'Su tel茅fono:')
->setHtmlType('tel')
->setHtmlAttribute('placeholder', 'Por favor, introduzca su tel茅fono');
```

Podemos establecer el atributo HTML a elementos individuales en listas de radio o casillas de verificaci贸n con valores diferentes para cada uno de ellos.
Tenga en cuenta los dos puntos despu茅s de `style:` para asegurarse de que el valor se selecciona por clave:
.[warning]
Establecer el tipo y otros atributos s贸lo sirve a efectos visuales. La verificaci贸n de la correcci贸n de la entrada debe ocurrir en el servidor, lo que puede asegurar eligiendo un [control de formulario | controls] apropiado y especificando [reglas de validaci贸n | validation].

Para elementos individuales en listas de radio o casillas de verificaci贸n, podemos establecer un atributo HTML con valores diferentes para cada uno de ellos.
Observe los dos puntos despu茅s de `style:`, que garantiza que el valor se selecciona en funci贸n de la clave:

```php
$colors = ['r' => 'red', 'g' => 'green', 'b' => 'blue'];
Expand All @@ -482,10 +485,9 @@ Renders:
<label><input type="checkbox" name="colors[]" value="b">blue</label>
```

Para un atributo HTML l贸gico (que no tiene valor, como `readonly`), puede utilizar un signo de interrogaci贸n:
Para establecer atributos booleanos, como `readonly`, podemos utilizar la notaci贸n con un signo de interrogaci贸n:

```php
$colors = ['r' => 'red', 'g' => 'green', 'b' => 'blue'];
$form->addCheckboxList('colors', 'Colors:', $colors)
->setHtmlAttribute('readonly?', 'r'); // use array for multiple keys, e.g. ['r', 'g']
```
Expand Down Expand Up @@ -539,9 +541,6 @@ Para los elementos Checkbox, CheckboxList y RadioList se puede influir en la pla

```php
$input = $form->addCheckbox('send');
echo $input->getControl();
// <label><input type="checkbox" name="send"></label>

$html = $input->getContainerPrototype();
$html->setName('div'); // <div>
$html->class('check'); // <div class="check">
Expand Down

0 comments on commit 3af79c4

Please sign in to comment.