Skip to content

Commit 62d4c63

Browse files
Merge pull request javascript-tutorial#333 from nahuelcoder/nahuelcoder-form-events
Events: change, input, cut, copy, paste
2 parents 15e3723 + 0b8adf2 commit 62d4c63

File tree

4 files changed

+67
-67
lines changed

4 files changed

+67
-67
lines changed

2-ui/4-forms-controls/3-events-change-input/1-deposit-calculator/solution.view/index.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,33 @@
2323

2424
<body>
2525

26-
Deposit calculator.
26+
Calculadora de depósito.
2727

2828
<form name="calculator">
2929
<table>
3030
<tr>
31-
<td>Initial deposit</td>
31+
<td>Depósito inicial</td>
3232
<td>
3333
<input name="money" type="number" value="10000" required>
3434
</td>
3535
</tr>
3636
<tr>
37-
<td>How many months?</td>
37+
<td>¿Cuántos meses?</td>
3838
<td>
3939
<select name="months">
40-
<option value="3">3 (minimum)</option>
41-
<option value="6">6 (half-year)</option>
42-
<option value="12" selected>12 (one year)</option>
43-
<option value="18">18 (1.5 years)</option>
44-
<option value="24">24 (2 years)</option>
45-
<option value="30">30 (2.5 years)</option>
46-
<option value="36">36 (3 years)</option>
47-
<option value="60">60 (5 years)</option>
40+
<option value="3">3 (mínimo)</option>
41+
<option value="6">6 (medio año)</option>
42+
<option value="12" selected>12 (un año)</option>
43+
<option value="18">18 (1.5 años)</option>
44+
<option value="24">24 (2 años)</option>
45+
<option value="30">30 (2.5 años)</option>
46+
<option value="36">36 (3 años)</option>
47+
<option value="60">60 (5 años)</option>
4848
</select>
4949
</td>
5050
</tr>
5151
<tr>
52-
<td>Interest per year?</td>
52+
<td>¿Interés anual?</td>
5353
<td>
5454
<input name="interest" type="number" value="5" required>
5555
</td>
@@ -62,8 +62,8 @@
6262

6363
<table id="diagram">
6464
<tr>
65-
<th>Was:</th>
66-
<th>Becomes:</th>
65+
<th>Inicial:</th>
66+
<th>Final:</th>
6767
</tr>
6868
<tr>
6969
<th id="money-before"></th>

2-ui/4-forms-controls/3-events-change-input/1-deposit-calculator/source.view/index.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,33 @@
2323

2424
<body>
2525

26-
Deposit calculator.
26+
Calculadora de depósito.
2727

2828
<form name="calculator">
2929
<table>
3030
<tr>
31-
<td>Initial deposit</td>
31+
<td>Depósito inicial</td>
3232
<td>
3333
<input name="money" type="number" value="10000" required>
3434
</td>
3535
</tr>
3636
<tr>
37-
<td>How many months?</td>
37+
<td>¿Cuántos meses?</td>
3838
<td>
3939
<select name="months">
40-
<option value="3">3 (minimum)</option>
41-
<option value="6">6 (half-year)</option>
42-
<option value="12" selected>12 (one year)</option>
43-
<option value="18">18 (1.5 years)</option>
44-
<option value="24">24 (2 years)</option>
45-
<option value="30">30 (2.5 years)</option>
46-
<option value="36">36 (3 years)</option>
47-
<option value="60">60 (5 years)</option>
40+
<option value="3">3 (mínimo)</option>
41+
<option value="6">6 (medio año)</option>
42+
<option value="12" selected>12 (un año)</option>
43+
<option value="18">18 (1.5 años)</option>
44+
<option value="24">24 (2 años)</option>
45+
<option value="30">30 (2.5 años)</option>
46+
<option value="36">36 (3 años)</option>
47+
<option value="60">60 (5 años)</option>
4848
</select>
4949
</td>
5050
</tr>
5151
<tr>
52-
<td>Interest per year?</td>
52+
<td>¿Interés anual?</td>
5353
<td>
5454
<input name="interest" type="number" value="5" required>
5555
</td>
@@ -62,8 +62,8 @@
6262

6363
<table id="diagram">
6464
<tr>
65-
<th>Was:</th>
66-
<th>Becomes:</th>
65+
<th>Inicial:</th>
66+
<th>Final:</th>
6767
</tr>
6868
<tr>
6969
<th id="money-before"></th>

2-ui/4-forms-controls/3-events-change-input/1-deposit-calculator/task.md

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

33
---
44

5-
# Deposit calculator
5+
# Calculadora de depósito
66

7-
Create an interface that allows to enter a sum of bank deposit and percentage, then calculates how much it will be after given periods of time.
7+
Crea una interfaz que permita ingresar una suma de depósito bancario y porcentaje, luego calcula cuánto será después de un periodo de tiempo determinado.
88

9-
Here's the demo:
9+
Acá una demostración:
1010

1111
[iframe src="solution" height="350" border="1"]
1212

13-
Any input change should be processed immediately.
13+
Cualquier modificación debe ser procesada de inmediato.
1414

15-
The formula is:
15+
La fórmula es:
1616
```js
17-
// initial: the initial money sum
18-
// interest: e.g. 0.05 means 5% per year
19-
// years: how many years to wait
17+
// initial: la suma inicial de dinero
18+
// interest: e.g. 0.05 significa 5% anual
19+
// years: cuántos años esperar
2020
let result = Math.round(initial * (1 + interest * years));
2121
```
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# Events: change, input, cut, copy, paste
1+
# Eventos: change, input, cut, copy, paste
22

3-
Let's cover various events that accompany data updates.
3+
Veamos varios eventos que acompañan la actualización de datos.
44

5-
## Event: change
5+
## Evento: change
66

7-
The `change` event triggers when the element has finished changing.
7+
El evento `change` se activa cuando el elemento finaliza un cambio.
88

9-
For text inputs that means that the event occurs when it loses focus.
9+
Para ingreso de texto significa que el evento ocurre cuando se pierde foco en el elemento.
1010

11-
For instance, while we are typing in the text field below -- there's no event. But when we move the focus somewhere else, for instance, click on a button -- there will be a `change` event:
11+
Por ejemplo, mientras estamos escribiendo en el siguiente cuadro de texto -- no hay evento. Pero cuando movemos el focus (enfoque) a otro lado, por ejemplo hacemos click en un botón, entonces ocurre el evento `change`:
1212

1313
```html autorun height=40 run
1414
<input type="text" onchange="alert(this.value)">
1515
<input type="button" value="Button">
1616
```
1717

18-
For other elements: `select`, `input type=checkbox/radio` it triggers right after the selection changes:
18+
Para otros elementos: `select`, `input type=checkbox/radio` ocurre justo después de cambiar la opción seleccionada:
1919

2020
```html autorun height=40 run
2121
<select onchange="alert(this.value)">
@@ -27,13 +27,13 @@ For other elements: `select`, `input type=checkbox/radio` it triggers right afte
2727
```
2828

2929

30-
## Event: input
30+
## Evento: input
3131

32-
The `input` event triggers every time after a value is modified by the user.
32+
El evento `input` ocurre cada vez que un valor es modificado por el ususario.
3333

34-
Unlike keyboard events, it triggers on any value change, even those that does not involve keyboard actions: pasting with a mouse or using speech recognition to dictate the text.
34+
A diferencia de los eventos de teclado, ocurre con el cambio a cualquier valor, incluso aquellos no que involucran acciones de teclado: copiar/pegar con el mouse o usar reconocimiento de voz para dictar texto.
3535

36-
For instance:
36+
Por ejemplo:
3737

3838
```html autorun height=40 run
3939
<input type="text" id="input"> oninput: <span id="result"></span>
@@ -44,25 +44,25 @@ For instance:
4444
</script>
4545
```
4646

47-
If we want to handle every modification of an `<input>` then this event is the best choice.
47+
Si queremos manejar cualquier modificación en un `<input>` entonces este evento es la mejor opción.
4848

49-
On the other hand, `input` event doesn't trigger on keyboard input and other actions that do not involve value change, e.g. pressing arrow keys `key:⇦` `key:⇨` while in the input.
49+
Por otro lado, el evento `input` no se activa con entradas del teclado u otras acciones que no involucren modificar un valor, e.g presionar las flechas de dirección `key:⇦` `key:⇨` mientras se está en el input.
5050

51-
```smart header="Can't prevent anything in `oninput`"
52-
The `input` event occurs after the value is modified.
51+
```smart header="No se puede evitar nada en `oninput`"
52+
El evento `input` ocurre después de que el valor es modificado.
5353

54-
So we can't use `event.preventDefault()` there -- it's just too late, there would be no effect.
54+
Por lo tanto no podemos usar `event.preventDefault()` para evitar modificaciones, en este caso ya es demasiado tarde por lo que no habría efecto.
5555
```
5656
57-
## Events: cut, copy, paste
57+
## Eventos: cut, copy, paste
5858
59-
These events occur on cutting/copying/pasting a value.
59+
Estos eventos ocurren al cortar/copiar/pegar un valor.
6060
61-
They belong to [ClipboardEvent](https://www.w3.org/TR/clipboard-apis/#clipboard-event-interfaces) class and provide access to the data that is copied/pasted.
61+
Estos pertenecen a la clase [ClipboardEvent](https://www.w3.org/TR/clipboard-apis/#clipboard-event-interfaces) y dan acceso a los datos copiados/pegados.
6262
63-
We also can use `event.preventDefault()` to abort the action, then nothing gets copied/pasted.
63+
También podemos usar `event.preventDefault()` para cancelar la acción y que nada sea copiado/pegado.
64+
Por ejemplo, el siguiente código evita tales eventos y muestra qué es los que estamos intentando cortar/copiar/pegar:
6465
65-
For instance, the code below prevents all such events and shows what we are trying to cut/copy/paste:
6666
6767
```html autorun height=40 run
6868
<input type="text" id="input">
@@ -74,20 +74,20 @@ For instance, the code below prevents all such events and shows what we are tryi
7474
</script>
7575
```
7676

77-
Please note, that it's possible to copy/paste not just text, but everything. For instance, we can copy a file in the OS file manager, and paste it.
77+
Por favor ten en cuenta que no solo es posible copiar/pegar texto, sino cualquier cosa. Por ejemplo, podemos copiar un archivo en el gestor de archivos del SO y pegarlo.
7878

79-
There's a list of methods [in the specification](https://www.w3.org/TR/clipboard-apis/#dfn-datatransfer) that can work with different data types including files, read/write to the clipboard.
79+
Hay una lista de métodos [en la especificación](https://www.w3.org/TR/clipboard-apis/#dfn-datatransfer) que puede funcionar con diferentes tipos de datos incluyendo archivos, leer/escribir del portapapeles.
8080

81-
But please note that clipboard is a "global" OS-level thing. Most browsers allow read/write access to the clipboard only in the scope of certain user actions for the safety, e.g. in `onclick` event handlers.
81+
Pero ten en cuenta que el portapapeles es algo a nivel "global" del SO. La mayoría de los navegadores dan acceso a leer/escribir del portapapeles dentro del alcance del usuario por cuestiones de seguridad, e.g. al manejar eventos `onclick`.
8282

83-
Also it's forbidden to generate "custom" clipboard events with `dispatchEvent` in all browsers except Firefox.
83+
Además está prohibido generar eventos "personalizados" del portapapeles con `dispatchEvent` en todos los navegadores excepto Firefox.
8484

85-
## Summary
85+
## Resumen
8686

87-
Data change events:
87+
Eventos de modificación de datos:
8888

89-
| Event | Description | Specials |
89+
| Evento | Descripción | Especiales |
9090
|---------|----------|-------------|
91-
| `change`| A value was changed. | For text inputs triggers on focus loss. |
92-
| `input` | For text inputs on every change. | Triggers immediately unlike `change`. |
93-
| `cut/copy/paste` | Cut/copy/paste actions. | The action can be prevented. The `event.clipboardData` property gives read/write access to the clipboard. |
91+
| `change`| Un valor fue cambiado. | Para ingreso de texto, ocurre al perderse el enfoque |
92+
| `input` | Para entrada de texto en cada cambio | Ocurre inmediatamente a diferencia de `change`. |
93+
| `cut/copy/paste` | Acciones cortar/copiar/pegar | La acción puede ser cancelada. La propiedad `event.clipboardData` brinda acceso a leer/escribir del portapeles. |

0 commit comments

Comments
 (0)