Skip to content

Commit 7acc02b

Browse files
authored
Merge pull request #234 from longo-andrea/article/forms
Forms: event and method submit
2 parents 7a801dc + 4256a73 commit 7acc02b

File tree

5 files changed

+48
-48
lines changed

5 files changed

+48
-48
lines changed

2-ui/4-forms-controls/1-form-elements/1-add-select-option/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The solution, step by step:
1+
La soluzione, passo per passo:
22

33
```html run
44
<select id="genres">

2-ui/4-forms-controls/1-form-elements/1-add-select-option/task.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# Add an option to select
5+
# Aggiungi un opzione di select
66

7-
There's a `<select>`:
7+
Abbiamo una select `<select>`:
88

99
```html
1010
<select id="genres">
@@ -13,10 +13,10 @@ There's a `<select>`:
1313
</select>
1414
```
1515

16-
Use JavaScript to:
16+
Utilizza JavaScript per:
1717

18-
1. Show the value and the text of the selected option.
19-
2. Add an option: `<option value="classic">Classic</option>`.
20-
3. Make it selected.
18+
1. Mostrare il valore ed il testo dell'opzione selezionata.
19+
2. Aggiungere un opzione: `<option value="classic">Classic</option>`.
20+
3. Selezionarla.
2121

22-
Note, if you've done everything right, your alert should show `blues`.
22+
Nota, se hai fatto tutto giusto, l'alert dovrebbe mostrare `blues`.

2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/solution.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
A modal window can be implemented using a half-transparent `<div id="cover-div">` that covers the whole window, like this:
1+
Una finestra modale può essere implementata usando un `<div id="cover-div">` semitrasparente che copre l'intera finestra, in questa maniera:
22

33
```css
44
#cover-div {
@@ -13,8 +13,8 @@ A modal window can be implemented using a half-transparent `<div id="cover-div">
1313
}
1414
```
1515

16-
Because the `<div>` covers everything, it gets all clicks, not the page below it.
16+
Dato che il `<div>` copre ogni cosa, sarà questo elemento a catturare tutti i click, e non la pagina sottostante.
1717

18-
Also we can prevent page scroll by setting `body.style.overflowY='hidden'`.
18+
Inoltre può essere prevenuto lo scrolling della pagina impostando `body.style.overflowY='hidden'`.
1919

20-
The form should be not in the `<div>`, but next to it, because we don't want it to have `opacity`.
20+
Il form non dovrebbe essere dentro il `<div>`, ma subito dopo nel codice della pagina (quindi starà anche sopra), perché non vogliamo che sia soggetto alla trasparenza dovuta ad `opacity`.

2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/task.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ importance: 5
44

55
# Modal form
66

7-
Create a function `showPrompt(html, callback)` that shows a form with the message `html`, an input field and buttons `OK/CANCEL`.
7+
Creare una funzione `showPrompt(html, callback)` che mostra un form con un messaggio `html`, un campo di input ed i pulsanti `OK/CANCEL`.
88

9-
- A user should type something into a text field and press `key:Enter` or the OK button, then `callback(value)` is called with the value they entered.
10-
- Otherwise if the user presses `key:Esc` or CANCEL, then `callback(null)` is called.
9+
- Un utente dovrebbe digitare qualcosa nel campo di testo e premere `key:Enter` o il pulsante OK, quindi verrà chiamata `callback(value)` con il valore che è stato inserito.
10+
- Altrimenti, se l'utente preme `key:Esc` oppure CANCEL, viene chiamata `callback(null)`.
1111

12-
In both cases that ends the input process and removes the form.
12+
In entrambi i casi, questo termina l'elaborazione dell'input e rimuove il form.
1313

14-
Requirements:
14+
Requisiti:
1515

16-
- The form should be in the center of the window.
17-
- The form is *modal*. In other words, no interaction with the rest of the page is possible until the user closes it.
18-
- When the form is shown, the focus should be inside the `<input>` for the user.
19-
- Keys `key:Tab`/`key:Shift+Tab` should shift the focus between form fields, don't allow it to leave for other page elements.
16+
- Il form dovrebbe essere al centro della finestra.
17+
- Il form è *modal*. In altre parole, non possono esserci interazioni con il resto della pagina fino a quando non viene chiusa.
18+
- Quando viene mostrato il form, il focus dovrebbe essere dentro il campo `<input>` per l'utente.
19+
- I tasti `key:Tab`/`key:Shift+Tab` dovrebbe cambiare il focus tra i campi del form, e non permettergli di lasciarlo per altri elementi della pagina.
2020

21-
Usage example:
21+
Un esempio di come dovrebbe funzionare:
2222

2323
```js
2424
showPrompt("Enter something<br>...smart :)", function(value) {
2525
alert(value);
2626
});
2727
```
2828

29-
A demo in the iframe:
29+
Una demo nell'iframe:
3030

3131
[iframe src="solution" height=160 border=1]
3232

33-
P.S. The source document has HTML/CSS for the form with fixed positioning, but it's up to you to make it modal.
33+
P.S.: Il sorgente del documento ha HTML e CSS per il form, con posizionamento fixed, ma sta a te renderla modale.

2-ui/4-forms-controls/4-forms-submit/article.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
# Forms: event and method submit
1+
# Form: eventi e metodi di submit
22

3-
The `submit` event triggers when the form is submitted, it is usually used to validate the form before sending it to the server or to abort the submission and process it in JavaScript.
3+
L'evento `submit` si scatena quando il form viene inviato, e solitamente viene usato per validare il form prima dell'invio al server o per annullare l'invio e elaborarlo con JavaScript.
44

5-
The method `form.submit()` allows to initiate form sending from JavaScript. We can use it to dynamically create and send our own forms to server.
5+
Il metodo `form.submit()` ci permette di iniziare l'invio del form da JavaScript. Possiamo usarlo per creare ed inviare i nostri form al server dinamicamente.
66

7-
Let's see more details of them.
7+
Andiamo più nel dettaglio.
88

9-
## Event: submit
9+
## Evento: submit
1010

11-
There are two main ways to submit a form:
11+
Ci sono due modi per inviare un form:
1212

13-
1. The first -- to click `<input type="submit">` or `<input type="image">`.
14-
2. The second -- press `key:Enter` on an input field.
13+
1. Il primo -- cliccare `<input type="submit">` o `<input type="image">`.
14+
2. Il secondo -- premere `key:Enter` su un campo di input.
1515

16-
Both actions lead to `submit` event on the form. The handler can check the data, and if there are errors, show them and call `event.preventDefault()`, then the form won't be sent to the server.
16+
Entrambe le azioni portano all'evento `submit` del form. Il gestore può controllare i dati, ed in caso di errori, può mostrarli e chiamare `event.preventDefault()`, ed a quel punto il form non viene inviato al server.
1717

18-
In the form below:
19-
1. Go into the text field and press `key:Enter`.
20-
2. Click `<input type="submit">`.
18+
Nel form seguente:
19+
1. Andare nel campo di testo e premere `key:Enter`.
20+
2. Cliccare `<input type="submit">`.
2121

22-
Both actions show `alert` and the form is not sent anywhere due to `return false`:
22+
Entrambe le azioni mostrano un `alert` ed il form non viene inviato da nessuna parte a causa di `return false`:
2323

2424
```html autorun height=60 no-beautify
2525
<form onsubmit="alert('submit!');return false">
26-
First: Enter in the input field <input type="text" value="text"><br>
27-
Second: Click "submit": <input type="submit" value="Submit">
26+
Primo: Entrare nel campo di testo <input type="text" value="text"><br>
27+
Secondo: Clicare "submit": <input type="submit" value="Submit">
2828
</form>
2929
```
3030

3131
````smart header="Relation between `submit` and `click`"
32-
When a form is sent using `key:Enter` on an input field, a `click` event triggers on the `<input type="submit">`.
32+
Quando un form viene inviato usando `key:Enter` su un campo di input, un evento `click` viene scaturito sull'elemento `<input type="submit">`.
3333

34-
That's rather funny, because there was no click at all.
34+
Ciò è piuttosto divertente, dal momento che non c'è stato nessun click.
3535

36-
Here's the demo:
36+
Ecco la demo:
3737
```html autorun height=60
3838
<form onsubmit="return false">
39-
<input type="text" size="30" value="Focus here and press enter">
39+
<input type="text" size="30" value="Porre il focus qui e premere Invio">
4040
<input type="submit" value="Submit" *!*onclick="alert('click')"*/!*>
4141
</form>
4242
```
4343

4444
````
4545
46-
## Method: submit
46+
## Metodo: submit
4747
48-
To submit a form to the server manually, we can call `form.submit()`.
48+
Per eseguire l'invio (submit) di un form sul server manualmente, possiamo chiamare `form.submit()`.
4949
50-
Then the `submit` event is not generated. It is assumed that if the programmer calls `form.submit()`, then the script already did all related processing.
50+
In questo caso l'evento di `submit` non viene generato. Si assume che il programmatore chiamando `form.submit()`, abbia previsto che nello script siano state considerate tutte le dovute elaborazioni.
5151
52-
Sometimes that's used to manually create and send a form, like this:
52+
Talvolta viene usato per creare ed inviare manualmente un form, come in questo esempio:
5353
5454
```js run
5555
let form = document.createElement('form');
@@ -58,7 +58,7 @@ form.method = 'GET';
5858
5959
form.innerHTML = '<input name="q" value="test">';
6060
61-
// the form must be in the document to submit it
61+
// il form deve essere nel documento per poterlo inviare
6262
document.body.append(form);
6363
6464
form.submit();

0 commit comments

Comments
 (0)