Skip to content

Commit 4d2e43f

Browse files
authored
Merge pull request #292 from shahrzadJavadiKoushesh/master-4
Forms: event and method submit
2 parents 2888d21 + cbb5115 commit 4d2e43f

File tree

3 files changed

+39
-38
lines changed

3 files changed

+39
-38
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+
یک modal window می‌تواند بااستفاده از یک `<div id="cover-div">` نیمه‌شفاف که تمام پنچره را می‌پوشاند پیاده‌سازی شود،‌ مثل این:
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+
از آنجایی که `<div>` همه چیز را می‌پوشاند، آن تمام کلیک‌ها را می‌گیرد،نه صفحه‌ی زیر آن.
1717

18-
Also we can prevent page scroll by setting `body.style.overflowY='hidden'`.
18+
همچنین با `body.style.overflowY='hidden'` می‌توانیم از scroll کردن صفحه جلوگیری کنیم.
1919

20-
The form should be not in the `<div>`, but next to it, because we don't want it to have `opacity`.
20+
فرم نباید در `<div>` باشد، بلکه باید کنار آن باشد، زیرا نمی‌خواهیم که `opacity` داشته باشد.

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ importance: 5
44

55
# Modal form
66

7-
Create a function `showPrompt(html, callback)` that shows a form with the message `html`, an input field and buttons `OK/CANCEL`.
7+
یک function `showPrompt(html, callback)` ایجاد کنید که فرمی با پیام `html`، یک input field و دکمه‌های `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+
- یک کاربر باید چیزی را در tex field تایپ کند و `key:Enter` را فشار دهد، آنگاه `callback(value)` با مقداری که وارد شده است فراخوانی می‌شود.
10+
- در غیر این صورت اگر کاربر `key:Esc` یا CANCEL را فشار دهد، `callback(null)` فراخوانی می‌شود.
1111

12-
In both cases that ends the input process and removes the form.
12+
در هر دو صورت،‌ این فرآیند input را تمام میکند و فرم را پاک میکند.
1313

14-
Requirements:
14+
ملزومات:
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+
- فرم باید در وسط پنجره باشد.
17+
- فرم یک *modal* است. به عبارت دیگر، تا زمانی که کاربر آن را نبندد، هیچ تعاملی با بقیه‌ی صفحه مجاز نیست.
18+
- وقتی فرم نمایش داده می‌شود، focus برای کاربر باید درون `<input>` باشد.
19+
- کلیدهای `key:Tab`/`key:Shift+Tab` باید فوکوس را بین form fieldها جابه‌جا کنند و اجازه ندهند که به عناصر دیگر صفحه برود.
2020

21-
Usage example:
21+
مثال از استفاده:
2222

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

29-
A demo in the iframe:
29+
نسخه‌ای نمایشی در 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+
پی‌نوشت: source documentای که ارائه شده HTML/CSS برای فرم با fixed positioning را دارد، اما این بر عهده‌ی شماست که آن را به modal تبدیل کنید.

2-ui/4-forms-controls/4-forms-submit/article.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
# Forms: event and method submit
1+
# فرم‌ها: event و method 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+
معمولا `submit` event زمانی فعال می‌شود که یک فرم submit می‌شود. معمولا برای اعتبارسنجی فرم قبل از اینکه به سمت سرور فرستاده شود یا لغو و پردازش آن در 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+
متد `form.submit()` اجازه می‌دهد که فرستادن فرم از JavaScript آغاز شود. ما می‌توانیم از آن استفاده کنیم که به صورت پویا فرم‌های خودمان را ایجاد کنیم و به سرور بفرستیم.
66

7-
Let's see more details of them.
7+
بیایید جزئیات بیشتری از آن‌ها ببینیم.
88

99
## Event: submit
1010

11-
There are two main ways to submit a form:
11+
دو راه اصلی برای submit کردن یک فرم وجود دارد.
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. اولی -- کلیک کردن `<input type="submit">` یا `<input type="image">`.
14+
2. دومی -- فشار دادن `key:Enter` روی یک input field.
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+
هر دو کار باعث `submit` event روی فرم می‌شوند. Handler می‌تواند داده را چک کند، و اگر خطاییی باشد، آن‌ها را نشان دهد و `event.preventDefault()` را فراخوانی کند، آنگاه فرم به سمت سرور ارسال نخواهد شد.
1717

18-
In the form below:
19-
1. Go into the text field and press `key:Enter`.
20-
2. Click `<input type="submit">`.
18+
در فرم زیر:
19+
1. به text field بعدی بروید و `key:Enter` را فشار دهید.
20+
2. روی `<input type="submit">` کلیک کنید.
2121

22-
Both actions show `alert` and the form is not sent anywhere due to `return false`:
22+
هر دو فعالیت `alert` را نمایش می‌دهند و فرم به دلیل `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+
را بزنید enter ،input field در <input type="text" value="text"><br>
27+
را کلیک کنید "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="`click` و `submit` ارتباط میان"
32+
.فعال می‌شود `<input type="submit">` روی `click` event فرستاده می‌شود یک `key:Enter` با input field وقتی که یک فرم در یک
3333

34-
That's rather funny, because there was no click at all.
34+
این نسبتا خنده‌دار است زیرا هیچ کلیکی اصلا وجود نداشته است.
3535

36-
Here's the demo:
36+
در اینجا نسخه‌ی نمایشی هست:
3737
```html autorun height=60
3838
<form onsubmit="return false">
39-
<input type="text" size="30" value="Focus here and press enter">
39+
<input type="text" size="30" value="اینجا فوکوس کنید">
4040
<input type="submit" value="Submit" *!*onclick="alert('click')"*/!*>
4141
</form>
4242
```
@@ -45,11 +45,12 @@ Here's the demo:
4545
4646
## Method: submit
4747
48-
To submit a form to the server manually, we can call `form.submit()`.
48+
برای اینکه یک فرم را به صورت دستی submit کنیم، می‌توانیم `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+
آنگاه `submit` event ایجاد نمی‌شود. تصور می‌شود که اگر برنامه‌نویس `form.submit()` را فراخونی کند، آنگاه script خودش تمام پردازش‌های مربوطه را انجام می‌دهد.
5151
5252
Sometimes that's used to manually create and send a form, like this:
53+
گاهی اوقات معمول ایت است که یک فرم را با این روش ایجاد و ارسال کنند.
5354
5455
```js run
5556
let form = document.createElement('form');
@@ -58,7 +59,7 @@ form.method = 'GET';
5859
5960
form.innerHTML = '<input name="q" value="test">';
6061
61-
// the form must be in the document to submit it
62+
// شود submit باشد تا document فرم باید در
6263
document.body.append(form);
6364
6465
form.submit();

0 commit comments

Comments
 (0)