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
Loading

0 comments on commit 3af79c4

Please sign in to comment.