Skip to content

Commit 85b14d2

Browse files
authored
Merge pull request #454 from puntope/Forms-event-and-method-submit
Forms: event and method submit
2 parents 88fd19f + 7cbe071 commit 85b14d2

File tree

5 files changed

+54
-54
lines changed

5 files changed

+54
-54
lines changed

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 ventana modal puede ser implementada utilizando un `<div id="cover-div">` semi-transparente que cubra completamente la ventana, como a continuación:
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+
Debido a que el `<div>` cubre toda la ventana, recibe todos los clicks, en vez de la página tras él.
1717

18-
Also we can prevent page scroll by setting `body.style.overflowY='hidden'`.
18+
También podemos evitar el scroll en la página utilizando `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+
El formulario no debe estar en el `<div>` sino junto a él, porque no queremos que tenga `opacity`.

2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/solution.view/index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88

99
<body style="height:3000px">
1010

11-
<h2>Click the button below</h2>
11+
<h2>Pulsa el botón de abajo</h2>
1212

13-
<input type="button" value="Click to show the form" id="show-button">
13+
<input type="button" value="Click aquí para mostrar el formulario" id="show-button">
1414

1515

1616
<div id="prompt-form-container">
1717
<form id="prompt-form">
1818
<div id="prompt-message"></div>
1919
<input name="text" type="text">
2020
<input type="submit" value="Ok">
21-
<input type="button" name="cancel" value="Cancel">
21+
<input type="button" name="cancel" value="Cancelar">
2222
</form>
2323
</div>
2424

2525
<script>
26-
// Show a half-transparent DIV to "shadow" the page
27-
// (the form is not inside, but near it, because it shouldn't be half-transparent)
26+
// Mostrar un DIV semi-transparente para cubrir la página.
27+
// (el formulario no está dentro sino junto a él, porque no debe tener transparencia.
2828
function showCover() {
2929
let coverDiv = document.createElement('div');
3030
coverDiv.id = 'cover-div';
3131

32-
// make the page unscrollable while the modal form is open
32+
// evitar el scroll en la página cuando el modal esta abierto
3333
document.body.style.overflowY = 'hidden';
3434

3535
document.body.append(coverDiv);
@@ -56,7 +56,7 @@ <h2>Click the button below</h2>
5656

5757
form.onsubmit = function() {
5858
let value = form.text.value;
59-
if (value == '') return false; // ignore empty submit
59+
if (value == '') return false; // ignorar submit vacíos
6060

6161
complete(value);
6262
return false;
@@ -94,8 +94,8 @@ <h2>Click the button below</h2>
9494
}
9595

9696
document.getElementById('show-button').onclick = function() {
97-
showPrompt("Enter something<br>...smart :)", function(value) {
98-
alert("You entered: " + value);
97+
showPrompt("Escribe algo<br>...inteligente :)", function(value) {
98+
alert("Escribiste: " + value);
9999
});
100100
};
101101
</script>

2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/source.view/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
<div id="prompt-form-container">
1313
<form id="prompt-form">
14-
<div id="prompt-message">Enter something...
15-
<br>Please..</div>
14+
<div id="prompt-message">Escribe algo...
15+
<br>Por favor...</div>
1616
<input name="text" type="text">
1717
<input type="submit" value="Ok">
18-
<input type="button" name="cancel" value="Cancel">
18+
<input type="button" name="cancel" value="Cancelar">
1919
</form>
2020
</div>
2121

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

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

33
---
44

5-
# Modal form
5+
# Formulario modal
66

7-
Create a function `showPrompt(html, callback)` that shows a form with the message `html`, an input field and buttons `OK/CANCEL`.
7+
Crea una función `showPrompt(html, callback)` que muestre un formulario con el mensaje `html`, un campo input y botones `OK/CANCELAR`.
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 usuario debe escribir algo en el campo de texto y pulsar `key:Enter` o el botón OK, entonces `callback(value)` es llamado con el valor introducido.
10+
- En caso contrario, si el usuario pulsa `key:Esc` o CANCELAR, entonces `callback(null)` es llamado.
1111

12-
In both cases that ends the input process and removes the form.
12+
En ambos casos se finaliza el proceso se y borra el formulario.
1313

14-
Requirements:
14+
Requisitos:
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+
- El formulario debe estar en el centro de la ventana.
17+
- El formulario es *modal*. Es decir que no habrá interacción con el resto de la página, siempre que sea posible, hasta que el usuario lo cierre.
18+
- Cuando se muestra el formulario, el foco debe estar en el `<input>` del usuario.
19+
- Las teclas `key:Tab`/`key:Shift+Tab` deben alternar el foco entre los diferentes campos del formulario, no se permite cambiar el foco a otros elementos de la página.
2020

21-
Usage example:
21+
Ejemplo de uso:
2222

2323
```js
24-
showPrompt("Enter something<br>...smart :)", function(value) {
24+
showPrompt("Escribe algo<br>...inteligente :)", function(value) {
2525
alert(value);
2626
});
2727
```
2828

29-
A demo in the iframe:
29+
Demo en el 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. El código fuente tiene el HTML/CSS para el formulario con posición fija. Pero tú decides cómo haces el modal.

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+
# Formularios: evento y método 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+
El evento `submit` se activa cuando el formlario es enviado, normalmente se utiliza para validar el formulario antes de ser enviado al servidor o bien para abortar el envío y procesarlo 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+
El método `form.submit()` permite iniciar el envío del formulario mediante JavaScript. Podemos utilizarlo para crear y enviar nuestros propios formularios al servidor.
66

7-
Let's see more details of them.
7+
Veamos más detalles sobre ellos.
88

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

11-
There are two main ways to submit a form:
11+
Mayormente un formulario puede enviarse de dos maneras:
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. La primera -- Haciendo click en `<input type="submit">` o en `<input type="image">`.
14+
2. La segunda -- Pulsando la tecla `key:Enter` en un campo del formulario.
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+
Ambas acciones causan que el evento `submit` sea activado en el formulario. El handler puede comprobar los datos, y si hay errores, mostrarlos e invocar `event.preventDefault()`, entonces el formulario no será enviado al servidor.
1717

18-
In the form below:
19-
1. Go into the text field and press `key:Enter`.
20-
2. Click `<input type="submit">`.
18+
En el formulario de abajo:
19+
1. Ve al campo tipo texto y pulsa la tecla `key:Enter`.
20+
2. Haz click en `<input type="submit">`.
2121

22-
Both actions show `alert` and the form is not sent anywhere due to `return false`:
22+
Ambas acciones muestran `alert` y el formulario no es enviado debido a la presencia de `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+
Primero: Enter en el campo de texto <input type="text" value="texto"><br>
27+
Segundo: Click en "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+
Cuando un formulario es enviado utlizando `key:Enter` en un campo tipo texto, un evento `click` se genera en el `<input type="submit">`
3333

34-
That's rather funny, because there was no click at all.
34+
Muy curioso, dado que no hubo ningún click en absoluto.
3535

36-
Here's the demo:
36+
Aquí esta 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="Sitúa el cursor aquí y pulsa Enter">
4040
<input type="submit" value="Submit" *!*onclick="alert('click')"*/!*>
4141
</form>
4242
```
4343

4444
````
4545
46-
## Method: submit
46+
## Método: submit
4747
48-
To submit a form to the server manually, we can call `form.submit()`.
48+
Para enviar un formulario al servidor manualmente, podemos usar `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+
Entonces el evento `submit` no será generado. Se asume que si el programador llama `form.submit()`, entonces el script ya realizó todo el procesamiento relacionado.
5151
52-
Sometimes that's used to manually create and send a form, like this:
52+
A veces es usado para crear y enviar un formlario manualmente, como en este ejemplo:
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+
// el formulario debe estar en el document para poder enviarlo
6262
document.body.append(form);
6363
6464
form.submit();

0 commit comments

Comments
 (0)