Skip to content

Commit d892aff

Browse files
authored
Merge pull request #32 from galtalmor/forms-translation
Translate Forms page
2 parents a3b61eb + 31ad493 commit d892aff

File tree

1 file changed

+61
-59
lines changed

1 file changed

+61
-59
lines changed

content/docs/forms.md

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: forms
3-
title: Forms
3+
title: טפסים
44
permalink: docs/forms.html
55
prev: lists-and-keys.html
66
next: lifting-state-up.html
@@ -9,27 +9,27 @@ redirect_from:
99
- "docs/forms-zh-CN.html"
1010
---
1111

12-
HTML form elements work a little bit differently from other DOM elements in React, because form elements naturally keep some internal state. For example, this form in plain HTML accepts a single name:
12+
אלמנטים של טפסיHTML עובדים מעט מאשר אלמנטים אחרים של ה-DOM ב-React, מכיוון שאלמנטים של טפסים באופן טבעי שומרים על state פנימי. למשל, הטופב הבא ב-HTML פשוט מקבל שם אחד:
1313

1414
```html
1515
<form>
1616
<label>
17-
Name:
17+
שם:
1818
<input type="text" name="name" />
1919
</label>
2020
<input type="submit" value="Submit" />
2121
</form>
2222
```
2323

24-
This form has the default HTML form behavior of browsing to a new page when the user submits the form. If you want this behavior in React, it just works. But in most cases, it's convenient to have a JavaScript function that handles the submission of the form and has access to the data that the user entered into the form. The standard way to achieve this is with a technique called "controlled components".
24+
לטופס זה יש את התנהגות ברירת המחדל של טפסי HTML של מעבר לדף חדש כאשר המשתמש שולח את הטופס. אם אתם רוצים את התנהגות זו ב-React, ככה זה עובד. אבל ברוב המקרים, זה נוח שיש פונקצית JavaScript המטפלת בשליחת הטופס ויש לה גישה לנתונים שהמשתמש הכניס לטופס. הדרך הסטנדרטית להשיג זאת היא באמצעות טכניקה הנקראת "קומפוננטות מבוקרות".
2525

26-
## Controlled Components {#controlled-components}
26+
## קומפוננטות מבוקרות {#controlled-components}
2727

28-
In HTML, form elements such as `<input>`, `<textarea>`, and `<select>` typically maintain their own state and update it based on user input. In React, mutable state is typically kept in the state property of components, and only updated with [`setState()`](/docs/react-component.html#setstate).
28+
ב-HTML, אלמנטים של טופס כגון `<input>`, `<textarea>`, ו-`<select>`שומרים בדרך כלל על מצבם ומעדכנים אותו על סמך קלט מהמשתמש. ב-React, `state` בר-שינוי נשמר בדרך כלל במאפייני ה-state של קומפוננטות, ומעודכן רק עם [`setState()`](/docs/react-component.html#setstate).
2929

30-
We can combine the two by making the React state be the "single source of truth". Then the React component that renders a form also controls what happens in that form on subsequent user input. An input form element whose value is controlled by React in this way is called a "controlled component".
30+
אנחנו יכולים לשלב את השניים על ידי הפיכת ה-state של React להיות "single source of truth" (מקור אמת יחיד). לאחר מכן קומפוננטת ה-React שמרנדרת טופס גם שולטת במה שקורה באותו טופס על קלט המשתמש הבא. קלט מאלמנט טופס שערכו נשלט על ידי React בדרך זו נקרא "קומפוננטה מבוקרת".
3131

32-
For example, if we want to make the previous example log the name when it is submitted, we can write the form as a controlled component:
32+
לדוגמה, אם אנחנו רוצים לשנות את הדוגמה הקודמת כך שתרשום ל-log את השם כאשר הטופס נשלח, אנחנו יכולים לרשום את הטופס כקומפונטה מבוקרת:
3333

3434
```javascript{4,10-12,24}
3535
class NameForm extends React.Component {
@@ -46,54 +46,54 @@ class NameForm extends React.Component {
4646
}
4747
4848
handleSubmit(event) {
49-
alert('A name was submitted: ' + this.state.value);
49+
alert('שם חדש נשלח: ' + this.state.value);
5050
event.preventDefault();
5151
}
5252
5353
render() {
5454
return (
5555
<form onSubmit={this.handleSubmit}>
5656
<label>
57-
Name:
57+
שם:
5858
<input type="text" value={this.state.value} onChange={this.handleChange} />
5959
</label>
60-
<input type="submit" value="Submit" />
60+
<input type="submit" value="שלח" />
6161
</form>
6262
);
6363
}
6464
}
6565
```
6666

67-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/VmmPgp?editors=0010)
67+
[**נסו זאת ב-CodePen**](https://codepen.io/gaearon/pen/VmmPgp?editors=0010)
6868

69-
Since the `value` attribute is set on our form element, the displayed value will always be `this.state.value`, making the React state the source of truth. Since `handleChange` runs on every keystroke to update the React state, the displayed value will update as the user types.
69+
מאחר שהתכונה `value` מוגדרת על אלמנט הטופס שלנו, הערך המוצג תמיד יהיה `this.state.value`, מה שהופך את ה-state של React ל-source of truth (מקור האמת). מכיוון ש-`handleChange` פועל על כל הקשה כדי לעדכן את ה-state של React, הערך המוצג יעודכן בזמן שהמשתמש מקליד.
7070

71-
With a controlled component, every state mutation will have an associated handler function. This makes it straightforward to modify or validate user input. For example, if we wanted to enforce that names are written with all uppercase letters, we could write `handleChange` as:
71+
עם קומפוננטה מבוקרת, לכל שינוי של ה-state תהיה פונקציה מטפלת מקושרת אליו. זה הופך את זה לממש פשוט לשנות או לאמת קלט משתמש. לדוגמה, אם רצינו לאכוף את השמות כך שיהיו כתובים באותיות גדולות, נוכל לכתוב את `handleChange` כך:
7272

7373
```javascript{2}
7474
handleChange(event) {
7575
this.setState({value: event.target.value.toUpperCase()});
7676
}
7777
```
7878

79-
## The textarea Tag {#the-textarea-tag}
79+
## תגית ה-textarea {#the-textarea-tag}
8080

81-
In HTML, a `<textarea>` element defines its text by its children:
81+
ב-HTML, אלמנט `<textarea>` מגדיר את הטקסט שלו על ידי הילדים שלו:
8282

8383
```html
8484
<textarea>
85-
Hello there, this is some text in a text area
85+
היי, זה מעט טקסט ב-textarea
8686
</textarea>
8787
```
8888

89-
In React, a `<textarea>` uses a `value` attribute instead. This way, a form using a `<textarea>` can be written very similarly to a form that uses a single-line input:
89+
ב-React, `<textarea>` משתמש במאפיין `value` במקום. בדרך זו, טופס המשתמש ב-`<textarea>` יכול להכתב באופן מאוד דומה לטופס המשתמש ב-input של שורה אחת:
9090

9191
```javascript{4-6,12-14,26}
9292
class EssayForm extends React.Component {
9393
constructor(props) {
9494
super(props);
9595
this.state = {
96-
value: 'Please write an essay about your favorite DOM element.'
96+
value: 'אנא כתבו מאמר אודות אלמנט ה-DOM האהוב עליכם.'
9797
};
9898
9999
this.handleChange = this.handleChange.bind(this);
@@ -105,7 +105,7 @@ class EssayForm extends React.Component {
105105
}
106106
107107
handleSubmit(event) {
108-
alert('An essay was submitted: ' + this.state.value);
108+
alert('מאמר נשלח: ' + this.state.value);
109109
event.preventDefault();
110110
}
111111
@@ -116,29 +116,29 @@ class EssayForm extends React.Component {
116116
Essay:
117117
<textarea value={this.state.value} onChange={this.handleChange} />
118118
</label>
119-
<input type="submit" value="Submit" />
119+
<input type="submit" value="שלח" />
120120
</form>
121121
);
122122
}
123123
}
124124
```
125125

126-
Notice that `this.state.value` is initialized in the constructor, so that the text area starts off with some text in it.
126+
שימו לב ש-`this.state.value` מאותחל בבנאי, כך שה-text area מאותחל עם קצת טקסט בתוכו.
127127

128-
## The select Tag {#the-select-tag}
128+
## תגית select {#the-select-tag}
129129

130-
In HTML, `<select>` creates a drop-down list. For example, this HTML creates a drop-down list of flavors:
130+
ב-HTML, `<select>` מייצר רשימה נפתחת. למשל, ה-HTML הבא מייצר רשימה נפתחת של טעמים:
131131

132132
```html
133133
<select>
134-
<option value="grapefruit">Grapefruit</option>
135-
<option value="lime">Lime</option>
136-
<option selected value="coconut">Coconut</option>
137-
<option value="mango">Mango</option>
134+
<option value="grapefruit">אשכולית</option>
135+
<option value="lime">ליים</option>
136+
<option selected value="coconut">קוקוס</option>
137+
<option value="mango">מנגו</option>
138138
</select>
139139
```
140140

141-
Note that the Coconut option is initially selected, because of the `selected` attribute. React, instead of using this `selected` attribute, uses a `value` attribute on the root `select` tag. This is more convenient in a controlled component because you only need to update it in one place. For example:
141+
שימו לב שהאפשרות קוקוס נבחרה תחילה, בגלל השימוש במאפיין`selected`. React, במקום להשתמש במאפיין `selected`, משתמשת במאפיין `value` של תגית השורש `select`. זה נוח יותר בקומפוננטה מבוקרת מכיוון שאתם צריכים לעדכן אותו רק במקום אחד. לדוגמה:
142142

143143
```javascript{4,10-12,24}
144144
class FlavorForm extends React.Component {
@@ -155,7 +155,7 @@ class FlavorForm extends React.Component {
155155
}
156156
157157
handleSubmit(event) {
158-
alert('Your favorite flavor is: ' + this.state.value);
158+
alert('הטעם האהוב עליך: ' + this.state.value);
159159
event.preventDefault();
160160
}
161161
@@ -165,46 +165,48 @@ class FlavorForm extends React.Component {
165165
<label>
166166
Pick your favorite flavor:
167167
<select value={this.state.value} onChange={this.handleChange}>
168-
<option value="grapefruit">Grapefruit</option>
169-
<option value="lime">Lime</option>
170-
<option value="coconut">Coconut</option>
171-
<option value="mango">Mango</option>
168+
<option value="grapefruit">אשכולית</option>
169+
<option value="lime">ליים</option>
170+
<option value="coconut">קוקוס</option>
171+
<option value="mango">מנגו</option>
172172
</select>
173173
</label>
174-
<input type="submit" value="Submit" />
174+
<input type="submit" value="שלח" />
175175
</form>
176176
);
177177
}
178178
}
179179
```
180180

181-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/JbbEzX?editors=0010)
181+
[**נסו זאת ב-CodePen**](https://codepen.io/gaearon/pen/JbbEzX?editors=0010)
182182

183-
Overall, this makes it so that `<input type="text">`, `<textarea>`, and `<select>` all work very similarly - they all accept a `value` attribute that you can use to implement a controlled component.
183+
באופן כללי, זה גורם לכך ש-`<input type="text">`, `<textarea>`, ו-`<select>` כולם עובדים באופן מאוד דומה - כולם מקבלים מאפיין `value` שבו ניתן להשתמש כדי לממש קומפוננטה מבוקרת.
184184

185-
> Note
185+
> הערה
186186
>
187-
> You can pass an array into the `value` attribute, allowing you to select multiple options in a `select` tag:
187+
> ניתן להעביר למאפיין `value` מערך, המאפשר לכם לבחור אפשרויות מרובות בתגית `select`:
188188
>
189189
>```js
190190
><select multiple={true} value={['B', 'C']}>
191191
>```
192192
193-
## The file input Tag {#the-file-input-tag}
193+
## תגית ה-file input {#the-file-input-tag}
194194
195-
In HTML, an `<input type="file">` lets the user choose one or more files from their device storage to be uploaded to a server or manipulated by JavaScript via the [File API](https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications).
195+
ב-HTML, תגית `<input type="file">` מאפשרת למשתמש לבחור קובץ אחד או יותר מזכרון המכשיר שלהם להעלאה לשרת או לביצוע מניפולציות על ידי JavaScript דרך ה-[File API](https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications).
196196
197197
```html
198198
<input type="file" />
199199
```
200200
201-
Because its value is read-only, it is an **uncontrolled** component in React. It is discussed together with other uncontrolled components [later in the documentation](/docs/uncontrolled-components.html#the-file-input-tag).
202201

203-
## Handling Multiple Inputs {#handling-multiple-inputs}
204202

205-
When you need to handle multiple controlled `input` elements, you can add a `name` attribute to each element and let the handler function choose what to do based on the value of `event.target.name`.
203+
מכיוון שהערך שלו הוא לקריאה בלבד, זוהי קומפוננטה **שאינה מבוקרת** ב-React. היא נדונה בהרחבה יחד עם קומפוננטות בלתי מבוקרות אחרות [בשלב מאוחר יותר בתיעוד](/docs/uncontrolled-components.html#the-file-input-tag).
206204

207-
For example:
205+
## טיפול בקלטים מרובים {#handling-multiple-inputs}
206+
207+
כאשר אתם צריכים להתמודד עם מספר אלמנטי `input` מבוקרים, אתם יכולים להוסיף מאפיין `name` לכל אלמנט ולתת לפונקציה המטפלת לבחור מה לעשות על סמך הערך של `event.target.name`.
208+
209+
לדוגמה:
208210

209211
```javascript{15,18,28,37}
210212
class Reservation extends React.Component {
@@ -232,7 +234,7 @@ class Reservation extends React.Component {
232234
return (
233235
<form>
234236
<label>
235-
Is going:
237+
מגיעים:
236238
<input
237239
name="isGoing"
238240
type="checkbox"
@@ -241,7 +243,7 @@ class Reservation extends React.Component {
241243
</label>
242244
<br />
243245
<label>
244-
Number of guests:
246+
מספר אורחים:
245247
<input
246248
name="numberOfGuests"
247249
type="number"
@@ -254,45 +256,45 @@ class Reservation extends React.Component {
254256
}
255257
```
256258

257-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/wgedvV?editors=0010)
259+
[**נסו זאת ב-CodePen**](https://codepen.io/gaearon/pen/wgedvV?editors=0010)
258260

259-
Note how we used the ES6 [computed property name](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names) syntax to update the state key corresponding to the given input name:
261+
שימו לב כיצד אנו משתמשים בתחביר [שם מאפיין מחושב](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names) של ES6 כדי לעדכן את מפתח ה-state בהתאמה לשם הקלט שהתקבל:
260262

261263
```js{2}
262264
this.setState({
263265
[name]: value
264266
});
265267
```
266268

267-
It is equivalent to this ES5 code:
269+
זה שווה ערך לקוד ה-ES5 הזה:
268270

269271
```js{2}
270272
var partialState = {};
271273
partialState[name] = value;
272274
this.setState(partialState);
273275
```
274276

275-
Also, since `setState()` automatically [merges a partial state into the current state](/docs/state-and-lifecycle.html#state-updates-are-merged), we only needed to call it with the changed parts.
277+
בנוסף, מאחר ש-`setState()` [ממזגת state חלקי ל-state הנוכחי](/docs/state-and-lifecycle.html#state-updates-are-merged) אוטומטית, אנחנו רק צריכים לקרוא לה עם החלקים השתנו.
276278

277-
## Controlled Input Null Value {#controlled-input-null-value}
279+
## ערך ריק בקלט מבוקר {#controlled-input-null-value}
278280

279-
Specifying the value prop on a [controlled component](/docs/forms.html#controlled-components) prevents the user from changing the input unless you desire so. If you've specified a `value` but the input is still editable, you may have accidentally set `value` to `undefined` or `null`.
281+
ציון ערך ה-prop על [קומפוננטה מבוקרת](/docs/forms.html#controlled-components) מונעת מהמשתמש לשנות את הקלט אלא אם כן אתם חפצים בכך. אם ציינתם ערך `value` אבל ה-input עדיין ניתן לעריכה, יכול להיות שבטעות הגדרתם את `value` ל-`undefined` או `null`.
280282

281-
The following code demonstrates this. (The input is locked at first but becomes editable after a short delay.)
283+
הקוד הבא מדגים זאת. (ה-input נעול בהתחלה, אך הופך לניתן לעריכה לאחר עיכוב קצר).
282284

283285
```javascript
284-
ReactDOM.render(<input value="hi" />, mountNode);
286+
ReactDOM.render(<input value="היי" />, mountNode);
285287

286288
setTimeout(function() {
287289
ReactDOM.render(<input value={null} />, mountNode);
288290
}, 1000);
289291

290292
```
291293

292-
## Alternatives to Controlled Components {#alternatives-to-controlled-components}
294+
## אלטרנטיבות לקומפוננטות מבוקרות {#alternatives-to-controlled-components}
293295

294-
It can sometimes be tedious to use controlled components, because you need to write an event handler for every way your data can change and pipe all of the input state through a React component. This can become particularly annoying when you are converting a preexisting codebase to React, or integrating a React application with a non-React library. In these situations, you might want to check out [uncontrolled components](/docs/uncontrolled-components.html), an alternative technique for implementing input forms.
296+
זה יכול לפעמים להיות מייגע להשתמש בקומפוננטות מבוקרות, כי אתם צריכים לכתוב מטפל אירוע עבור כל דרך בה הנתונים שלכם יכולים להשתנות ולשרשר את כל מצבי הקלט באמצעות קומפוננטת React. זה יכול להיות מעצבן במיוחד כאשר אתם ממירים קוד קוד קיים ל-React, או משלבים אפליקציית React עם ספרייה שאינה React. במצבים אלו, ייתכן שתרצו לבדוק על [קומפוננטות בלתי מבוקרות](/docs/uncontrolled-components.html), טכניקה חלופית למימוש טפסי קלט.
295297

296-
## Fully-Fledged Solutions {#fully-fledged-solutions}
298+
## פתרונות כוללים {#fully-fledged-solutions}
297299

298-
If you're looking for a complete solution including validation, keeping track of the visited fields, and handling form submission, [Formik](https://jaredpalmer.com/formik) is one of the popular choices. However, it is built on the same principles of controlled components and managing state — so don't neglect to learn them.
300+
אם אתם מחפשים פתרון מלא הכולל אימות, מעקב אחר שדות שבוקרו, וטיפול בשליחת טופס, [Formik](https://jaredpalmer.com/formik) היא אחת האפשרויות הפופולריות. עם זאת, הוא בנוי על אותם עקרונות של קומפוננטות מבוקרות וניהול state — אז אל תזניחו לימוד שלהם.

0 commit comments

Comments
 (0)