diff --git a/2-ui/4-forms-controls/1-form-elements/1-add-select-option/task.md b/2-ui/4-forms-controls/1-form-elements/1-add-select-option/task.md index a0e74da57..e73cb934a 100644 --- a/2-ui/4-forms-controls/1-form-elements/1-add-select-option/task.md +++ b/2-ui/4-forms-controls/1-form-elements/1-add-select-option/task.md @@ -2,9 +2,9 @@ importance: 5 --- -# Add an option to select +# اضافه کردن یک option به select -There's a `` وجود دارد: ```html `: ``` -Use JavaScript to: +از JavaScript استفاده کنید تا: -1. Show the value and the text of the selected option. -2. Add an option: ``. -3. Make it selected. +1. مقدار و متن selected option را نشان دهید. +2. یک option اضافه کنید: ``. +3. ان را selected بکنید. -Note, if you've done everything right, your alert should show `blues`. +توجه کنید که اگر همه چیز را درست انجام داده باشید alert باید `blues` را نشان دهد. diff --git a/2-ui/4-forms-controls/1-form-elements/article.md b/2-ui/4-forms-controls/1-form-elements/article.md index f22518d9d..48c7ad1ca 100644 --- a/2-ui/4-forms-controls/1-form-elements/article.md +++ b/2-ui/4-forms-controls/1-form-elements/article.md @@ -1,23 +1,24 @@ -# Form properties and methods +# Form properties و methods -Forms and control elements, such as `` have a lot of special properties and events. +فرم‌ها و control elementها مثل `` دارای prperty و eventهای ویژه‌ای هستند. -Working with forms will be much more convenient when we learn them. +وقتی فرم‌ها را یاد بگیریم، کار کردن با آن‌ها بسیار راحت‌تر می‌شود. ## Navigation: form and elements -Document forms are members of the special collection `document.forms`. +فرم‌های document از اعضای مجموعه‌ی ویژه‌ی `document.forms` هستند. + +این به اصطلاح یک مجموعه‌ی نام‌گذاری شده است: هم نام‌گذاری شده و هم ترتیب‌دار شده است. برای دسترسی به فرم می‌توانیم هم از نام آن و هم از شماره‌ی آن در document استفاده کنیم. -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. ```js no-beautify -document.forms.my; // the form with name="my" -document.forms[0]; // the first form in the document +document.forms.my; // "my" = فرم با نام +document.forms[0]; // document اولین فرم در ``` -When we have a form, then any element is available in the named collection `form.elements`. +وقتی یک فرم داریم،‌ در این صورت هر elementای در مجموعه‌ی نام‌گذاری شده با `form.elements` قابل دسترسی است. -For instance: +برای مثال: ```html run height=40
@@ -26,19 +27,19 @@ For instance:
``` -There may be multiple elements with the same name. This is typical with radio buttons and checkboxes. +ممکن است elementهای زیادی با نام یکسان وجود داشته باشند. این در مورد radio buttonها و checkboxها معمول است. -In that case, `form.elements[name]` is a *collection*. For instance: +در آن صورت، `form.elements[name]` یک *مجموعه*‌است. برای مثال:‌ ```html run height=40
@@ -57,11 +58,11 @@ alert(ageElems[0]); // [object HTMLInputElement] ``` -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`. +این navigation propertyها به tag structure وابستگی ندارند. تمام control elementها، فرقی ندارد چقدر در فرم عمیق باشند، در `form.elements` قابل دسترسی هستند. ````smart header="Fieldsets as \"subforms\"" -A form may have one or many `
` elements inside it. They also have `elements` property that lists form controls inside them. +.را درون خود فهرست می‌کنند form controls دارند که `elements` property در خودش داشته باشد. آن‌ها همچنین `
` elements یک فرم ممکن است یک یا چند For instance: @@ -81,7 +82,7 @@ For instance: let fieldset = form.elements.userFields; alert(fieldset); // HTMLFieldSetElement - // we can get the input by name both from the form and from the fieldset + // .دریافت کنیم fieldset و هم از form را با نام هم از input ما می‌توانیم alert(fieldset.elements.login == form.elements.login); // true */!* @@ -89,14 +90,14 @@ For instance: ``` ```` -````warn header="Shorter notation: `form.name`" -There's a shorter notation: we can access the element as `form[index/name]`. +````warn header="نماد کوتاه‌تر: `form.name`" +.دسترسی داشته باشیم element به `form[index/name]` کوتاه‌تر هم وجود دارد: ما می‌توانیم با notation یک -In other words, instead of `form.elements.login` we can write `form.login`. +به عبارت دیگر، به جای `form.elements.login` می‌توانیم بنویسیم `form.login`. -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). +آن هم کار می‌کند، ولی یک مشکل جزئی وجود دارد: اگر به یک element دسترسی داشته باشیم، و بعد `name` آن را تغییر بدهیم، آنگاه آن هنوز با نام قدیمی قابل دسترسی است (همچنین با نام جدید) -That's easy to see in an example: +آسان‌تر است که آن را در یک مثال ببینیم: ```html run height=40 @@ -104,34 +105,34 @@ That's easy to see in an example: ``` -That's usually not a problem, however, because we rarely change names of form elements. +با این حال، این معمولا یک مشکل نیست، چون ما به ندرت نام elementهای فرم را تغییر می‌دهیم. ```` ## Backreference: element.form -For any element, the form is available as `element.form`. So a form references all elements, and elements reference the form. +برای هر elementای، فرم به عنوان `element.form` قابل دسترسی است. بنابراین یک فرم به همه‌ی elementها ارجاع می‌دهد و elementها هم به فرم ارجاع می‌دهند. -Here's the picture: +این هم تصویرش است: ![](form-navigation.svg) -For instance: +برای مثال: ```html run height=40
@@ -151,64 +152,64 @@ For instance: ## Form elements -Let's talk about form controls. +.صحبت کنیم form controls بیایید درباره‌ی ### input and textarea -We can access their value as `input.value` (string) or `input.checked` (boolean) for checkboxes and radio buttons. +.به مقدار آن‌ها دسترسی داشته باشیم radio buttons و checkboxes برای `input.value` (string) یا `input.checked` (boolean) ما می‌توانیم با -Like this: +مثل این: ```js -input.value = "New value"; -textarea.value = "New text"; +input.value = "جدید value"; +textarea.value = "جدید text"; -input.checked = true; // for a checkbox or radio button +input.checked = true; // radio button یا checkbox برای یک ``` -```warn header="Use `textarea.value`, not `textarea.innerHTML`" -Please note that even though `` holds its value as nested HTML, we should never use `textarea.innerHTML` to access it. +```warn header="Use `textarea.value`, نه `textarea.innerHTML`" +.به آن دسترسی داشته باشیم `textarea.innerHTML` تو در تو حفظ می‌کند اما ما هرگز نباید از طریق HTML مقدار خود را به عنوان `` لطفا توجه کنید که با اینکه -It stores only the HTML that was initially on the page, not the current value. +.که در ابتدا در صفحه بوده را ذخیره می‌کند، نه مقدار فعلی را HTML آن فقط ``` -### select and option +### select و option -A `` element یک -1. `select.options` -- the collection of ` +// ایجاد می‌کند ``` -The same option, but selected: +شده select اما option همان ```js let option = new Option("Text", "value", true, true); ``` -Option elements have properties: +:دارند property یک سری Option elements `option.selected` -: Is the option selected. +: انتخاب شده است یا نه option `option.index` -: The number of the option among the others in its `` در بین بقیه option عدد : `option.text` -: Text content of the option (seen by the visitor). +(توسط بازدیدکننده دیده می‌شود) option محتوای متنی : -## References +## منابع -- Specification: . +- جزئیات: . -## Summary +## خلاصه Form navigation: `document.forms` -: A form is available as `document.forms[name/index]`. +.قابل دسترسی است `document.forms[name/index]` یک فرم با : `form.elements` -: Form elements are available as `form.elements[name/index]`, or can use just `form[name/index]`. The `elements` property also works for `
`. +.کار می‌کنند `
` همچنین با `elements` property استفاده کرد. `form[name/index]` قابل دسترسی هستند، یا فقط می‌توان از `form.elements[name/index]` با Form elements عناصر : `element.form` -: Elements reference their form in the `form` property. +.به فرم خود ارجاع می‌دهند `form` property عناصر در : -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.) +(.استفاده کنید که مشخص می‌کند یک مقدار انتخاب شده است یا نه `input.checked` از radio buttons و checkboxes برای) و ... قابل دسترسی است. `input.value`، `textarea.value`، `select.value` با value مقدار -For `` برای -These are the basics to start working with forms. We'll meet many examples further in the tutorial. +این‌ها مبانی شروع کار با فرم‌ها هستند. ما مثال‌های بیشتری را در آموزش خواهیم دید. -In the next chapter we'll cover `focus` and `blur` events that may occur on any element, but are mostly handled on forms. +.را پوشش خواهیم داد که ممکن است در هر عنصری اتفاق بیفتند، اما بیشتر در فرم‌ها مدیریت می‌شوند `blur` و `focus` در فصل بعدی ما