Skip to content

Commit 597dd00

Browse files
authored
Merge pull request #449 from brunacborgesm/feature/form-submit-event
Forms: event and method submit
2 parents 0424be5 + 689a92d commit 597dd00

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
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+
Uma janela de modal pode ser implementada usando um elemento semitransparente `<div id="cover-div">` que cobre toda a janela, como por exemplo:
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+
Por conta da `<div>` cobrir todo o espaço, irá capturar todos os cliques feito dentro nela, e não na página abaixo dela.
1717

18-
Also we can prevent page scroll by setting `body.style.overflowY='hidden'`.
18+
Também podemos impedir a rolagem da página definindo `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+
O formulário não deve estar dentro da `<div>`, mas sim ao lado dela, porque não queremos que ele tenha `opacity`.

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

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

33
---
44

5-
# Modal form
5+
# Formuário 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+
Crie uma função `showPrompt(html, callback)` onde mostra um formulário com uma mensagem `html`, um campo de entrada e botões `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+
- Um usuário deve esprever algo dentro do campo de texto e pressionar `key:Enter` ou o botão de OK button, então é chamado o `callback(value)` com o valor que foi inserido.
10+
- Porém, se o usuário pressionar `key:Esc` ou CANCEL, então `callback(null)` é chamado.
1111

12-
In both cases that ends the input process and removes the form.
12+
Em ambos os casos, isso encerra o processo de entrada e remove o formulário.
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+
- O formulário deve estar no centro da janela.
17+
- O formulário é um *modal*. Em outras palavras, não será possível interagir com o restante da página até que o usuário a feche.
18+
- Quando o formulário for exibido, o foco do usuário deverá estar dentro do campo `<input>`.
19+
- As teclas `key:Tab`/`key:Shift+Tab` devem alternar o foco entre os campos do formulário, não permitindo que o foco saia para outros elementos da página.
2020

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

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

29-
A demo in the iframe:
29+
Uma demonstração dentro de um 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+
Obs: O documento de origem contém HTML/CSS para o formulário com posicionamento fixo, mas cabe a você torná-lo um 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,39 +1,39 @@
1-
# Forms: event and method submit
1+
# Formulários: evento e 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+
O evento `submit` é disparado quando o formulário é submetido. Geralmente, é usado para validar o formulário antes de enviá-lo ao servidor ou para abortar o envio e processá-lo no 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+
O método `form.submit()` permite iniciar o envio de formulários a partir do JavaScript. Podemos usá-lo para criar e enviar dinamicamente nossos próprios formulários para o servidor.
66

7-
Let's see more details of them.
7+
Vamos ver mais detalhes sobre eles.
88

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

11-
There are two main ways to submit a form:
11+
Há duas maneiras principais de enviar um formulário:
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. A Primeira -- clicar em `<input type="submit">` ou `<input type="image">`.
14+
2. A Segunda -- pressione `key:Enter` em um campo de 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+
Ambas as ações levam a execução do evento `submit` no formulário. O handler pode verificar os dados, e se houver erros, será mostrado e chamado o `event.preventDefault()`, logo, o formulário não será enviado para o 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+
No formulário abaixo:
19+
1. Vá para o campo de texto e pressione `key:Enter`.
20+
2. Clique em `<input type="submit">`.
2121

22-
Both actions show `alert` and the form is not sent anywhere due to `return false`:
22+
Ambas as ações mostram um `alert` e o formulário não é enviado a lugar nenhum devido ao `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+
Primeiro: Insira no campo de entrada <input type="text" value="text"><br>
27+
Segundo: Clique em "submit": <input type="submit" value="Submit">
2828
</form>
2929
```
3030

31-
````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">`.
31+
````smart header="Relação entre `submit` e `click`"
32+
Quando um formulário é enviado usando `key:Enter` no campo de entrada, um evento de `click` dispara no `<input type="submit">`.
3333

34-
That's rather funny, because there was no click at all.
34+
Isso é até bem engraçado, porque não houve nenhum clique.
3535

36-
Here's the demo:
36+
Aqui está uma demonstração:
3737
```html autorun height=60
3838
<form onsubmit="return false">
3939
<input type="text" size="30" value="Focus here and press enter">
@@ -43,13 +43,13 @@ Here's the demo:
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 um formulário ao servidor manualmente, podemos chamar `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+
Nesse caso, o evento `submit` não é gerado. Podemos presumir que, se o programador chamar `form.submit()`, o script já terá realizado todo o processamento relacionado.
5151
52-
Sometimes that's used to manually create and send a form, like this:
52+
Às vezes, isso é usado para criar e enviar um formulário manualmente, como este:
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+
// o formulário deve estar incluído no documento para que ele seja enviado.
6262
document.body.append(form);
6363
6464
form.submit();

0 commit comments

Comments
 (0)