Skip to content

Commit aa40d0c

Browse files
authored
Merge pull request #285 from shahrzadJavadiKoushesh/master-2
Form properties and methods
2 parents 791ffdf + c6bf9bd commit aa40d0c

File tree

2 files changed

+92
-91
lines changed

2 files changed

+92
-91
lines changed

2-ui/4-forms-controls/1-form-elements/1-add-select-option/task.md

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

33
---
44

5-
# Add an option to select
5+
# اضافه کردن یک option به select
66

7-
There's a `<select>`:
7+
یک `<select>` وجود دارد:
88

99
```html
1010
<select id="genres">
@@ -13,10 +13,10 @@ There's a `<select>`:
1313
</select>
1414
```
1515

16-
Use JavaScript to:
16+
از JavaScript استفاده کنید تا:
1717

18-
1. Show the value and the text of the selected option.
19-
2. Add an option: `<option value="classic">Classic</option>`.
20-
3. Make it selected.
18+
1. مقدار و متن selected option را نشان دهید.
19+
2. یک option اضافه کنید: `<option value="classic">Classic</option>`.
20+
3. ان را selected بکنید.
2121

22-
Note, if you've done everything right, your alert should show `blues`.
22+
توجه کنید که اگر همه چیز را درست انجام داده باشید alert باید `blues` را نشان دهد.
Lines changed: 85 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
# Form properties and methods
1+
# Form properties و methods
22

3-
Forms and control elements, such as `<input>` have a lot of special properties and events.
3+
فرم‌ها و control elementها مثل `<input>` دارای prperty و eventهای ویژه‌ای هستند.
44

5-
Working with forms will be much more convenient when we learn them.
5+
وقتی فرم‌ها را یاد بگیریم، کار کردن با آن‌ها بسیار راحت‌تر می‌شود.
66

77
## Navigation: form and elements
88

9-
Document forms are members of the special collection `document.forms`.
9+
فرم‌های document از اعضای مجموعه‌ی ویژه‌ی `document.forms` هستند.
10+
11+
این به اصطلاح یک مجموعه‌ی نام‌گذاری شده است: هم نام‌گذاری شده و هم ترتیب‌دار شده است. برای دسترسی به فرم می‌توانیم هم از نام آن و هم از شماره‌ی آن در document استفاده کنیم.
1012

11-
That's a so-called *"named collection"*: it's both named and ordered. We can use both the name or the number in the document to get the form.
1213

1314
```js no-beautify
14-
document.forms.my; // the form with name="my"
15-
document.forms[0]; // the first form in the document
15+
document.forms.my; // "my" = فرم با نام
16+
document.forms[0]; // document اولین فرم در
1617
```
1718

18-
When we have a form, then any element is available in the named collection `form.elements`.
19+
وقتی یک فرم داریم،‌ در این صورت هر elementای در مجموعه‌ی نام‌گذاری شده با `form.elements` قابل دسترسی است.
1920

20-
For instance:
21+
برای مثال:
2122

2223
```html run height=40
2324
<form name="my">
@@ -26,19 +27,19 @@ For instance:
2627
</form>
2728

2829
<script>
29-
// get the form
30+
// form گرفتن
3031
let form = document.forms.my; // <form name="my"> element
3132
32-
// get the element
33+
// element گرفتن
3334
let elem = form.elements.one; // <input name="one"> element
3435
3536
alert(elem.value); // 1
3637
</script>
3738
```
3839

39-
There may be multiple elements with the same name. This is typical with radio buttons and checkboxes.
40+
ممکن است elementهای زیادی با نام یکسان وجود داشته باشند. این در مورد radio buttonها و checkboxها معمول است.
4041

41-
In that case, `form.elements[name]` is a *collection*. For instance:
42+
در آن صورت، `form.elements[name]` یک *مجموعه*‌است. برای مثال:‌
4243

4344
```html run height=40
4445
<form>
@@ -57,11 +58,11 @@ alert(ageElems[0]); // [object HTMLInputElement]
5758
</script>
5859
```
5960

60-
These navigation properties do not depend on the tag structure. All control elements, no matter how deep they are in the form, are available in `form.elements`.
61+
این navigation propertyها به tag structure وابستگی ندارند. تمام control elementها، فرقی ندارد چقدر در فرم عمیق باشند، در `form.elements` قابل دسترسی هستند.
6162

6263

6364
````smart header="Fieldsets as \"subforms\""
64-
A form may have one or many `<fieldset>` elements inside it. They also have `elements` property that lists form controls inside them.
65+
.را درون خود فهرست می‌کنند form controls دارند که `elements` property در خودش داشته باشد. آن‌ها همچنین `<fieldset>` elements یک فرم ممکن است یک یا چند
6566
6667
For instance:
6768
@@ -81,57 +82,57 @@ For instance:
8182
let fieldset = form.elements.userFields;
8283
alert(fieldset); // HTMLFieldSetElement
8384
84-
// we can get the input by name both from the form and from the fieldset
85+
// .دریافت کنیم fieldset و هم از form را با نام هم از input ما می‌توانیم
8586
alert(fieldset.elements.login == form.elements.login); // true
8687
*/!*
8788
</script>
8889
</body>
8990
```
9091
````
9192

92-
````warn header="Shorter notation: `form.name`"
93-
There's a shorter notation: we can access the element as `form[index/name]`.
93+
````warn header="نماد کوتاه‌تر: `form.name`"
94+
.دسترسی داشته باشیم element به `form[index/name]` کوتاه‌تر هم وجود دارد: ما می‌توانیم با notation یک
9495

95-
In other words, instead of `form.elements.login` we can write `form.login`.
96+
به عبارت دیگر، به جای `form.elements.login` می‌توانیم بنویسیم `form.login`.
9697

97-
That also works, but there's a minor issue: if we access an element, and then change its `name`, then it is still available under the old name (as well as under the new one).
98+
آن هم کار می‌کند، ولی یک مشکل جزئی وجود دارد: اگر به یک element دسترسی داشته باشیم، و بعد `name` آن را تغییر بدهیم، آنگاه آن هنوز با نام قدیمی قابل دسترسی است (همچنین با نام جدید)
9899

99-
That's easy to see in an example:
100+
آسان‌تر است که آن را در یک مثال ببینیم:
100101

101102
```html run height=40
102103
<form id="form">
103104
<input name="login">
104105
</form>
105106

106107
<script>
107-
alert(form.elements.login == form.login); // true, the same <input>
108+
alert(form.elements.login == form.login); // true, همان <input>
108109
109-
form.login.name = "username"; // change the name of the input
110+
form.login.name = "username"; // را تغییر می‌دهد input نام
110111
111-
// form.elements updated the name:
112+
// می‌کند update را name، forms.elements
112113
alert(form.elements.login); // undefined
113114
alert(form.elements.username); // input
114115
115116
*!*
116-
// form allows both names: the new one and the old one
117+
// را مجاز می‌کند: هم جدید و هم قدیمی name فرم هر دو
117118
alert(form.username == form.login); // true
118119
*/!*
119120
</script>
120121
```
121122

122-
That's usually not a problem, however, because we rarely change names of form elements.
123+
با این حال، این معمولا یک مشکل نیست، چون ما به ندرت نام elementهای فرم را تغییر می‌دهیم.
123124

124125
````
125126
126127
## Backreference: element.form
127128
128-
For any element, the form is available as `element.form`. So a form references all elements, and elements reference the form.
129+
برای هر elementای، فرم به عنوان `element.form` قابل دسترسی است. بنابراین یک فرم به همه‌ی elementها ارجاع می‌دهد و elementها هم به فرم ارجاع می‌دهند.
129130
130-
Here's the picture:
131+
این هم تصویرش است:
131132
132133
![](form-navigation.svg)
133134
134-
For instance:
135+
برای مثال:
135136
136137
```html run height=40
137138
<form id="form">
@@ -151,64 +152,64 @@ For instance:
151152
152153
## Form elements
153154
154-
Let's talk about form controls.
155+
.صحبت کنیم form controls بیایید درباره‌ی
155156
156157
### input and textarea
157158
158-
We can access their value as `input.value` (string) or `input.checked` (boolean) for checkboxes and radio buttons.
159+
.به مقدار آن‌ها دسترسی داشته باشیم radio buttons و checkboxes برای `input.value` (string) یا `input.checked` (boolean) ما می‌توانیم با
159160
160-
Like this:
161+
مثل این:
161162
162163
```js
163-
input.value = "New value";
164-
textarea.value = "New text";
164+
input.value = "جدید value";
165+
textarea.value = "جدید text";
165166
166-
input.checked = true; // for a checkbox or radio button
167+
input.checked = true; // radio button یا checkbox برای یک
167168
```
168169
169-
```warn header="Use `textarea.value`, not `textarea.innerHTML`"
170-
Please note that even though `<textarea>...</textarea>` holds its value as nested HTML, we should never use `textarea.innerHTML` to access it.
170+
```warn header="Use `textarea.value`, نه `textarea.innerHTML`"
171+
.به آن دسترسی داشته باشیم `textarea.innerHTML` تو در تو حفظ می‌کند اما ما هرگز نباید از طریق HTML مقدار خود را به عنوان `<textarea>...</textarea>` لطفا توجه کنید که با اینکه
171172
172-
It stores only the HTML that was initially on the page, not the current value.
173+
.که در ابتدا در صفحه بوده را ذخیره می‌کند، نه مقدار فعلی را HTML آن فقط
173174
```
174175
175-
### select and option
176+
### select و option
176177
177-
A `<select>` element has 3 important properties:
178+
:مهم دارد property سه `<select>` element یک
178179
179-
1. `select.options` -- the collection of `<option>` subelements,
180-
2. `select.value` -- the *value* of the currently selected `<option>`,
181-
3. `select.selectedIndex` -- the *number* of the currently selected `<option>`.
180+
1. `select.options` -- `<option>` subelements مجموعه‌ای از
181+
2. `select.value` -- در حال حاضر انتخاب شده `<option>` *مقدار*
182+
3. `select.selectedIndex` -- در حال حاضر انتخاب شده `<option>` *تعداد*
182183
183-
They provide three different ways of setting a value for a `<select>`:
184+
:عرضه می‌کنند `<select>` کردن یک مقدار برای set آن‌ها سه راه مختلف برای
184185
185-
1. Find the corresponding `<option>` element (e.g. among `select.options`) and set its `option.selected` to `true`.
186-
2. If we know a new value: set `select.value` to the new value.
187-
3. If we know the new option number: set `select.selectedIndex` to that number.
186+
1. .قرار می‌دهد `true` آن را برابر `option.selected` و مقدار (برای مثال `select.options`) متناظر را پیدا می‌کند `<option>` عنصر
187+
2. .را برابر آن مقدار جدید قرار می‌دهد `select.value` اگر یک مقدار جدید را بدانیم:
188+
3. .را برابر آن عدد قرار می‌دهد `select.selectedIndex` جدید را بدانیم: مقدار option number اگر
188189
189-
Here is an example of all three methods:
190+
:اینجا مثالی از هر سه متد می‌بینیم
190191
191192
```html run
192193
<select id="select">
193-
<option value="apple">Apple</option>
194-
<option value="pear">Pear</option>
195-
<option value="banana">Banana</option>
194+
<option value="apple">سیب</option>
195+
<option value="pear">گلابی</option>
196+
<option value="banana">موز</option>
196197
</select>
197198
198199
<script>
199-
// all three lines do the same thing
200+
// تمام سه خط کار یکسانی انجام می‌دهند
200201
select.options[2].selected = true;
201202
select.selectedIndex = 2;
202203
select.value = 'banana';
203-
// please note: options start from zero, so index 2 means the 3rd option.
204+
// .option از صفر شروع می‌شوند، پس اندیس دو یعنی سومین options :لطفا دقت داشته باشید
204205
</script>
205206
```
206207
207-
Unlike most other controls, `<select>` allows to select multiple options at once if it has `multiple` attribute. This attribute is rarely used, though.
208+
.به ندرت استفاده می‌شود attribute به طور همزمان انتخاب شوند. با این حال، این option داشته باشد، اجازه می‌دهد که چند attribute `چند` `<select>` های دیگر اگرcontrol برعکس بیشتر
208209
209-
For multiple selected values, use the first way of setting values: add/remove the `selected` property from `<option>` subelements.
210+
.حذف/به آن اضافه کنید `<option>` subelements را از `selected` property برای چندین مقدار انتخاب شده، از روش اول برای تنظیم مقادیر استفاده کنید
210211
211-
Here's an example of how to get selected values from a multi-select:
212+
:مقدار انتخاب‌شده را به دست آوریم ،multi-select اینجا یک مثال داریم از اینکه چگونه از یک
212213
213214
```html run
214215
<select id="select" *!*multiple*/!*>
@@ -218,7 +219,7 @@ Here's an example of how to get selected values from a multi-select:
218219
</select>
219220
220221
<script>
221-
// get all selected values from multi-select
222+
// multi-select گرفتن تمام مقادیر انتخاب‌شده از
222223
let selected = Array.from(select.options)
223224
.filter(option => option.selected)
224225
.map(option => option.value);
@@ -227,72 +228,72 @@ Here's an example of how to get selected values from a multi-select:
227228
</script>
228229
```
229230
230-
The full specification of the `<select>` element is available in the specification <https://html.spec.whatwg.org/multipage/forms.html#the-select-element>.
231+
.موجود است <https://html.spec.whatwg.org/multipage/forms.html#the-select-element> در مشخصات `<select>` element مشخصات کامل
231232
232-
### new Option
233+
### جدید Option
233234
234-
In the [specification](https://html.spec.whatwg.org/multipage/forms.html#the-option-element) there's a nice short syntax to create an `<option>` element:
235+
:وجود دارد <option>` element کوتاه و زیبا برای ایجاد یک syntax یک [مشخصات](https://html.spec.whatwg.org/multipage/forms.html#the-option-element) در
235236
236237
```js
237238
option = new Option(text, value, defaultSelected, selected);
238239
```
239240
240-
This syntax is optional. We can use `document.createElement('option')` and set attributes manually. Still, it may be shorter, so here are the parameters:
241+
:را به صورت دستی مقداردهی کنیم. با این حال،‌ ممکن است کوتاه‌تر باشد پس اینجا پارامترها وجود دارند attributes استقاده کنیم و `document.createElement('option')` اختیاری است، ما می‌توانیم از syntax این
241242
242-
- `text` -- the text inside the option,
243-
- `value` -- the option value,
244-
- `defaultSelected` -- if `true`, then `selected` HTML-attribute is created,
245-
- `selected` -- if `true`, then the option is selected.
243+
- `text` -- option متن درون,
244+
- `value` -- option مقدار,
245+
- `defaultSelected` -- ایجاد می‌شود `selected` HTML-attribute باشد `true` اگر
246+
- `selected` -- انتخاب می‌شود option باشد `true` اگر
246247
247-
The difference between `defaultSelected` and `selected` is that `defaultSelected` sets the HTML-attribute (that we can get using `option.getAttribute('selected')`, while `selected` sets whether the option is selected or not.
248+
.انتخاب شده است یا نه option مشخص می‌کند که آیا `selected` در حالی که (آن را بگیریم `option.getAttribute('selected')` که ما می‌توانیم با) می‌کند set را HTML-attribute مقدار `defaultSelected` در این است که `selected` و `defaultSelected` تفاوت بین
248249
249-
In practice, one should usually set _both_ values to `true` or `false`. (Or, simply omit them; both default to `false`.)
250+
(`false` یا به سادگی حذف شوند، مقدار پیش‌فرض هر دو) .باشند `false` یا `true` در عمل باید معمولا _هر دو_ مقدار
250251
251-
For instance, here's a new "unselected" option:
252+
برای مثال، اینجا بک "unselected" option داریم:
252253
253254
```js
254255
let option = new Option("Text", "value");
255-
// creates <option value="value">Text</option>
256+
// ایجاد می‌کند <option value="value">Text</option>
256257
```
257258
258-
The same option, but selected:
259+
شده select اما option همان
259260
260261
```js
261262
let option = new Option("Text", "value", true, true);
262263
```
263264
264-
Option elements have properties:
265+
:دارند property یک سری Option elements
265266
266267
`option.selected`
267-
: Is the option selected.
268+
: انتخاب شده است یا نه option
268269
269270
`option.index`
270-
: The number of the option among the others in its `<select>`.
271+
خودش `<select>` در بین بقیه option عدد :
271272
272273
`option.text`
273-
: Text content of the option (seen by the visitor).
274+
(توسط بازدیدکننده دیده می‌شود) option محتوای متنی :
274275
275-
## References
276+
## منابع
276277
277-
- Specification: <https://html.spec.whatwg.org/multipage/forms.html>.
278+
- جزئیات: <https://html.spec.whatwg.org/multipage/forms.html>.
278279
279-
## Summary
280+
## خلاصه
280281
281282
Form navigation:
282283
283284
`document.forms`
284-
: A form is available as `document.forms[name/index]`.
285+
.قابل دسترسی است `document.forms[name/index]` یک فرم با :
285286
286287
`form.elements`
287-
: Form elements are available as `form.elements[name/index]`, or can use just `form[name/index]`. The `elements` property also works for `<fieldset>`.
288+
.کار می‌کنند `<fieldset>` همچنین با `elements` property استفاده کرد. `form[name/index]` قابل دسترسی هستند، یا فقط می‌توان از `form.elements[name/index]` با Form elements عناصر :
288289
289290
`element.form`
290-
: Elements reference their form in the `form` property.
291+
.به فرم خود ارجاع می‌دهند `form` property عناصر در :
291292
292-
Value is available as `input.value`, `textarea.value`, `select.value`, etc. (For checkboxes and radio buttons, use `input.checked` to determine whether a value is selected.)
293+
(.استفاده کنید که مشخص می‌کند یک مقدار انتخاب شده است یا نه `input.checked` از radio buttons و checkboxes برای) و ... قابل دسترسی است. `input.value`، `textarea.value`، `select.value` با value مقدار
293294
294-
For `<select>`, one can also get the value by the index `select.selectedIndex` or through the options collection `select.options`.
295+
.به دست آورد options collection `select.options` یا از طریق `select.selectedIndex` همچنین می‌توان مقدار را با اندیس `<select>` برای
295296
296-
These are the basics to start working with forms. We'll meet many examples further in the tutorial.
297+
این‌ها مبانی شروع کار با فرم‌ها هستند. ما مثال‌های بیشتری را در آموزش خواهیم دید.
297298
298-
In the next chapter we'll cover `focus` and `blur` events that may occur on any element, but are mostly handled on forms.
299+
.را پوشش خواهیم داد که ممکن است در هر عنصری اتفاق بیفتند، اما بیشتر در فرم‌ها مدیریت می‌شوند `blur` و `focus` در فصل بعدی ما

0 commit comments

Comments
 (0)