You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/components/form.md
+39-39
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: "<form>"
4
4
5
5
<Intro>
6
6
7
-
The [built-in browser `<form>`component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)lets you create interactive controls for submitting information.
7
+
O [componente `<form>`do navegador embutido](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/form)permite que você crie controles interativos para enviar informações.
8
8
9
9
```js
10
10
<form action={search}>
@@ -19,11 +19,11 @@ The [built-in browser `<form>` component](https://developer.mozilla.org/en-US/do
19
19
20
20
---
21
21
22
-
## Reference {/*reference*/}
22
+
## Referência {/*reference*/}
23
23
24
24
### `<form>` {/*form*/}
25
25
26
-
To create interactive controls for submitting information, render the [built-in browser `<form>`component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form).
26
+
Para criar controles interativos para enviar informações, renderize o [componente `<form>`do navegador embutido](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/form).
27
27
28
28
```js
29
29
<form action={search}>
@@ -32,25 +32,25 @@ To create interactive controls for submitting information, render the [built-in
32
32
</form>
33
33
```
34
34
35
-
[See more examples below.](#usage)
35
+
[Veja mais exemplos abaixo.](#usage)
36
36
37
37
#### Props {/*props*/}
38
38
39
-
`<form>`supports all [common element props.](/reference/react-dom/components/common#props)
39
+
`<form>`suporta todas as [props de elementos comuns.](/reference/react-dom/components/common#props)
40
40
41
-
[`action`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#action): a URL or function. When a URL is passed to`action` the form will behave like the HTML form component. When a function is passed to`action` the function will handle the form submission. The function passed to`action`may be async and will be called with a single argument containing the [form data](https://developer.mozilla.org/en-US/docs/Web/API/FormData)of the submitted form. The `action`prop can be overridden by a`formAction`attribute on a`<button>`, `<input type="submit">`, or`<input type="image">` component.
41
+
[`action`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/form#action): uma URL ou função. Quando uma URL é passada para`action`, o formulário se comportará como o componente de formulário HTML. Quando uma função é passada para`action`, a função irá manipular o envio do formulário. A função passada para`action`pode ser async e será chamada com um único argumento contendo os [dados do formulário](https://developer.mozilla.org/pt-BR/docs/Web/API/FormData)do formulário enviado. A prop `action`pode ser substituída por um atributo`formAction`em um componente`<button>`, `<input type="submit">` ou`<input type="image">`.
42
42
43
-
#### Caveats {/*caveats*/}
43
+
#### Ressalvas {/*caveats*/}
44
44
45
-
*When a function is passed to`action`or`formAction` the HTTP method will be POST regardless of value of the`method` prop.
45
+
*Quando uma função é passada para`action`ou`formAction`, o método HTTP será POST, independentemente do valor da prop`method`.
46
46
47
47
---
48
48
49
-
## Usage {/*usage*/}
49
+
## Uso {/*usage*/}
50
50
51
-
### Handle form submission on the client {/*handle-form-submission-on-the-client*/}
51
+
### Manipular envio de formulário no cliente {/*handle-form-submission-on-the-client*/}
52
52
53
-
Pass a function to the `action`prop of form to run the function when the form is submitted. [`formData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)will be passed to the function as an argument so you can access the data submitted by the form. This differs from the conventional [HTML action](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#action), which only accepts URLs. After the `action` function succeeds, all uncontrolled field elements in the form are reset.
53
+
Passe uma função para a prop `action`do formulário para executar a função quando o formulário for enviado. [`formData`](https://developer.mozilla.org/pt-BR/docs/Web/API/FormData)será passado para a função como um argumento para que você possa acessar os dados enviados pelo formulário. Isso difere da [ação HTML](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/form#action) convencional, que aceita apenas URLs. Após a execução da função `action`, todos os elementos de campo não controlados no formulário são redefinidos.
54
54
55
55
<Sandpack>
56
56
@@ -71,13 +71,13 @@ export default function Search() {
71
71
72
72
</Sandpack>
73
73
74
-
### Handle form submission with a Server Function {/*handle-form-submission-with-a-server-function*/}
74
+
### Manipular envio de formulário com uma Server Function {/*handle-form-submission-with-a-server-function*/}
75
75
76
-
Render a`<form>`with an input and submit button. Pass a Server Function (a function marked with[`'use server'`](/reference/rsc/use-server)) to the `action`prop of form to run the function when the form is submitted.
76
+
Renderize um`<form>`com um input e um botão de envio. Passe uma Server Function (uma função marcada com[`'use server'`](/reference/rsc/use-server)) para a prop `action`do formulário para executar a função quando o formulário for enviado.
77
77
78
-
Passing a Server Function to`<form action>`allow users to submit forms without JavaScript enabled or before the code has loaded. This is beneficial to users who have a slow connection, device, or have JavaScript disabled and is similar to the way forms work when a URL is passed to the `action` prop.
78
+
Passar uma Server Function para`<form action>`permite que os usuários enviem formulários sem o JavaScript ativado ou antes que o código seja carregado. Isso é benéfico para usuários que têm uma conexão lenta, dispositivo ou têm o JavaScript desativado e é semelhante à maneira como os formulários funcionam quando uma URL é passada para a prop `action`.
79
79
80
-
You can use hidden form fields to provide data to the `<form>`'s action. The Server Function will be called with the hidden form field data as an instance of [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData).
80
+
Você pode usar campos de formulário ocultos para fornecer dados para a ação do `<form>`. A Server Function será chamada com os dados do campo de formulário oculto como uma instância de [`FormData`](https://developer.mozilla.org/pt-BR/docs/Web/API/FormData).
81
81
82
82
```jsx
83
83
import { updateCart } from'./lib.js';
@@ -98,7 +98,7 @@ function AddToCart({productId}) {
98
98
}
99
99
```
100
100
101
-
In lieu of using hidden form fields to provide data to the `<form>`'s action, you can call the <CodeStepstep={1}>`bind`</CodeStep> method to supply it with extra arguments. This will bind a new argument (<CodeStepstep={2}>`productId`</CodeStep>) to the function in addition to the <CodeStepstep={3}>`formData`</CodeStep> that is passed as an argument to the function.
101
+
Em vez de usar campos de formulário ocultos para fornecer dados à ação do `<form>`, você pode chamar o método <CodeStepstep={1}>`bind`</CodeStep> para fornecer argumentos extras. Isso vinculará um novo argumento (<CodeStepstep={2}>`productId`</CodeStep>) à função, além do <CodeStepstep={3}>`formData`</CodeStep> que é passado como argumento para a função.
@@ -117,12 +117,12 @@ function AddToCart({productId}) {
117
117
}
118
118
```
119
119
120
-
When `<form>`is rendered by a[Server Component](/reference/rsc/use-client), and a[Server Function](/reference/rsc/server-functions)is passed to the `<form>`'s`action`prop, the form is [progressively enhanced](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement).
120
+
Quando o `<form>`é renderizado por um[Server Component](/reference/rsc/use-client), e uma[Server Function](/reference/rsc/server-functions)é passada para a prop`action`do `<form>`, o formulário é [progressivamente aprimorado](https://developer.mozilla.org/pt-BR/docs/Glossary/Progressive_Enhancement).
121
121
122
-
### Display a pending state during form submission {/*display-a-pending-state-during-form-submission*/}
123
-
To display a pending state when a form is being submitted, you can call the `useFormStatus`Hook in a component rendered in a `<form>`and read the `pending`property returned.
122
+
### Exibir um estado pendente durante o envio do formulário {/*display-a-pending-state-during-form-submission*/}
123
+
Para exibir um estado pendente quando um formulário está sendo enviado, você pode chamar o Hook `useFormStatus`em um componente renderizado em um `<form>`e ler a propriedade `pending`retornada.
124
124
125
-
Here, we use the`pending`property to indicate the form is submitting.
125
+
Aqui, usamos a propriedade`pending`para indicar que o formulário está sendo enviado.
126
126
127
127
<Sandpack>
128
128
@@ -160,12 +160,12 @@ export async function submitForm(query) {
160
160
161
161
</Sandpack>
162
162
163
-
To learn more about the `useFormStatus` Hook see the [reference documentation](/reference/react-dom/hooks/useFormStatus).
163
+
Para saber mais sobre o Hook `useFormStatus`, consulte a [documentação de referência](/reference/react-dom/hooks/useFormStatus).
164
164
165
-
### Optimistically updating form data {/*optimistically-updating-form-data*/}
166
-
The `useOptimistic`Hook provides a way to optimistically update the user interface before a background operation, like a network request, completes. In the context of forms, this technique helps to make apps feel more responsive. When a user submits a form, instead of waiting for the server's response to reflect the changes, the interface is immediately updated with the expected outcome.
165
+
### Atualizando otimistamente dados do formulário {/*optimistically-updating-form-data*/}
166
+
O Hook `useOptimistic`fornece uma maneira de atualizar otimistamente a interface do usuário antes que uma operação em segundo plano, como uma solicitação de rede, seja concluída. No contexto de formulários, essa técnica ajuda a tornar os aplicativos mais responsivos. Quando um usuário envia um formulário, em vez de esperar pela resposta do servidor para refletir as alterações, a interface é imediatamente atualizada com o resultado esperado.
167
167
168
-
For example, when a user types a message into the form and hits the "Send" button, the `useOptimistic`Hook allows the message to immediately appear in the list with a "Sending..." label, even before the message is actually sent to a server. This "optimistic" approach gives the impression of speed and responsiveness. The form then attempts to truly send the message in the background. Once the server confirms the message has been received, the "Sending..." label is removed.
168
+
Por exemplo, quando um usuário digita uma mensagem no formulário e pressiona o botão "Enviar", o Hook `useOptimistic`permite que a mensagem apareça imediatamente na lista com um rótulo "Enviando...", mesmo antes que a mensagem seja realmente enviada para um servidor. Essa abordagem "otimista" dá a impressão de velocidade e responsividade. O formulário então tenta enviar a mensagem de verdade em segundo plano. Depois que o servidor confirma que a mensagem foi recebida, o rótulo "Enviando..." é removido.
169
169
170
170
<Sandpack>
171
171
@@ -229,12 +229,12 @@ export async function deliverMessage(message) {
229
229
230
230
</Sandpack>
231
231
232
-
[//]: #'Uncomment the next line, and delete this line after the `useOptimistic` reference documentatino page is published'
233
-
[//]: #'To learn more about the `useOptimistic` Hook see the [reference documentation](/reference/react/hooks/useOptimistic).'
232
+
[//]: #'Remova o comentário da próxima linha e exclua esta linha após a publicação da página de documentação de referência `useOptimistic`'
233
+
[//]: #'Para saber mais sobre o Hook `useOptimistic`, consulte a [documentação de referência](/reference/react/hooks/useOptimistic).'
234
234
235
-
### Handling form submission errors {/*handling-form-submission-errors*/}
235
+
### Lidando com erros de envio de formulário {/*handling-form-submission-errors*/}
236
236
237
-
In some cases the function called by a `<form>`'s `action` prop throws an error. You can handle these errors by wrapping`<form>`in an Error Boundary. If the function called by a `<form>`'s `action` prop throws an error, the fallback for the error boundary will be displayed.
237
+
Em alguns casos, a função chamada pela prop `action` de um `<form>` lança um erro. Você pode tratar esses erros envolvendo o`<form>`em um Error Boundary. Se a função chamada pela prop `action` de um `<form>` lançar um erro, o fallback para o error boundary será exibido.
238
238
239
239
<Sandpack>
240
240
@@ -274,15 +274,15 @@ export default function Search() {
274
274
275
275
</Sandpack>
276
276
277
-
### Display a form submission error without JavaScript {/*display-a-form-submission-error-without-javascript*/}
277
+
### Exibir um erro de envio de formulário sem JavaScript {/*display-a-form-submission-error-without-javascript*/}
278
278
279
-
Displaying a form submission error message before the JavaScript bundle loads for progressive enhancement requires that:
279
+
Exibir uma mensagem de erro de envio de formulário antes que o bundle JavaScript seja carregado para aprimoramento progressivo exige que:
280
280
281
-
1.`<form>`be rendered by a[Server Component](/reference/rsc/use-client)
282
-
1.the function passed to the `<form>`'s`action`prop be a[Server Function](/reference/rsc/server-functions)
283
-
1.the `useActionState`Hook be used to display the error message
281
+
1.`<form>`seja renderizado por um[Server Component](/reference/rsc/use-client)
282
+
1.a função passada para a prop`action`do `<form>` seja uma[Server Function](/reference/rsc/server-functions)
283
+
1.o Hook `useActionState`seja usado para exibir a mensagem de erro
284
284
285
-
`useActionState`takes two parameters: a[Server Function](/reference/rsc/server-functions)and an initial state. `useActionState`returns two values, a state variable and an action. The action returned by`useActionState`should be passed to the `action`prop of the form. The state variable returned by `useActionState`can be used to display an error message. The value returned by the Server Function passed to`useActionState`will be used to update the state variable.
285
+
`useActionState`recebe dois parâmetros: um[Server Function](/reference/rsc/server-functions)e um estado inicial. `useActionState`retorna dois valores, uma variável de estado e uma ação. A ação retornada por`useActionState`deve ser passada para a prop `action`do formulário. A variável de estado retornada por `useActionState`pode ser usada para exibir uma mensagem de erro. O valor retornado pela Server Function passada para`useActionState`será usado para atualizar a variável de estado.
286
286
287
287
<Sandpack>
288
288
@@ -330,13 +330,13 @@ export async function signUpNewUser(newEmail) {
330
330
331
331
</Sandpack>
332
332
333
-
Learn more about updating state from a form action with the [`useActionState`](/reference/react/useActionState) docs
333
+
Saiba mais sobre como atualizar o estado de uma ação de formulário com a documentação [`useActionState`](/reference/react/useActionState)
### Lidar com vários tipos de envio {/*handling-multiple-submission-types*/}
336
336
337
-
Forms can be designed to handle multiple submission actions based on the button pressed by the user. Each button inside a form can be associated with a distinct action or behavior by setting the `formAction` prop.
337
+
Os formulários podem ser projetados para lidar com várias ações de envio com base no botão pressionado pelo usuário. Cada botão dentro de um formulário pode ser associado a uma ação ou comportamento distinto definindo a prop `formAction`.
338
338
339
-
When a user taps a specific button, the form is submitted, and a corresponding action, defined by that button's attributes and action, is executed. For instance, a form might submit an article for review by default but have a separate button with `formAction`set to save the article as a draft.
339
+
Quando um usuário toca em um botão específico, o formulário é enviado e uma ação correspondente, definida pelos atributos e ação daquele botão, é executada. Por exemplo, um formulário pode, por padrão, enviar um artigo para revisão, mas ter um botão separado com o `formAction`definido para salvar o artigo como um rascunho.
340
340
341
341
<Sandpack>
342
342
@@ -364,4 +364,4 @@ export default function Search() {
0 commit comments