Skip to content

Commit c0e2bf8

Browse files
authored
Merge pull request #158 from Kirill255/master
translation of the /2-ui/4-forms-controls/4-forms-submit
2 parents 3da649f + e5a2f50 commit c0e2bf8

3 files changed

Lines changed: 47 additions & 45 deletions

File tree

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+
Модальное окно может быть реализовано с помощью полупрозрачного `<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'`.
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: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ importance: 5
22

33
---
44

5-
# Modal form
5+
# Модальное диалоговое окно с формой
66

7-
Create a function `showPrompt(html, callback)` that shows a form with the message `html`, an input field and buttons `OK/CANCEL`.
7+
Создайте функцию `showPrompt(html, callback)`, которая выводит форму с сообщением (`html`), полем ввода и кнопками `OK/ОТМЕНА`.
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+
- Пользователь должен ввести что-то в текстовое поле и нажать `key:Enter` или кнопку "OK", после чего должна вызываться функция `callback(value)` со значением поля.
10+
- Если пользователь нажимает `key:Esc` или кнопку "ОТМЕНА", тогда вызывается `callback(null)`.
1111

12-
In both cases that ends the input process and removes the form.
12+
В обоих случаях нужно завершить процесс ввода и закрыть диалоговое окно с формой.
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+
- Форма является *модальным окном*, это значит, что никакое взаимодействие с остальной частью страницы невозможно, пока пользователь не закроет его.
18+
- При показе формы, фокус должен находиться сразу внутри `<input>`.
19+
- Клавиши `key:Tab`/`key:Shift+Tab` должны переключать фокус между полями формы, не позволяя ему переходить к другим элементам страницы.
2020

21-
Usage example:
21+
Пример использования:
2222

2323
```js
24-
showPrompt("Enter something<br>...smart :)", function(value) {
24+
showPrompt("Введите что-нибудь<br>...умное :)", function(value) {
2525
alert(value);
2626
});
2727
```
2828

29-
A demo in the iframe:
29+
Демо в фрейме:
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+
P.S. HTML/CSS исходного кода к этой задаче содержит форму с фиксированным позиционированием, но вы должны сделать её модальной.

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

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,57 @@
1-
# Form submission: event and method submit
1+
# Отправка формы: событие и метод 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`, оно обычно используется для проверки (валидации) формы перед её отправкой на сервер или для предотвращения отправки и обработки её с помощью 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

9-
## Event: submit
9+
## Событие: submit
1010

11-
There are two main ways to submit a form:
11+
Есть два основных способа отправить форму:
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`, находясь на каком-нибудь поле.
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.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+
В примере ниже:
2119

22-
Both actions show `alert` and the form is not sent anywhere due to `return false`:
20+
1. Перейдите в текстовое поле и нажмите `key:Enter`.
21+
2. Нажмите `<input type="submit">`.
22+
23+
Оба действия показывают `alert` и форма не отправится благодаря `return false`:
2324

2425
```html autorun height=60 no-beautify
2526
<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">
27+
Первый пример: нажмите Enter: <input type="text" value="Текст"><br>
28+
Второй пример: нажмите на кнопку "Отправить": <input type="submit" value="Отправить">
2829
</form>
2930
```
3031

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">`.
32+
````smart header="Взаимосвязь между `submit` и `click`"
33+
При отправке формы по нажатию `key:Enter` в текстовом поле, генерируется событие `click` на кнопке `<input type="submit">`.
34+
35+
Это довольно забавно, учитывая что никакого клика не было.
3336

34-
That's rather funny, because there was no click at all.
37+
Пример:
3538

36-
Here's the demo:
3739
```html autorun height=60
38-
<form onsubmit="return false">
39-
<input type="text" size="30" value="Focus here and press enter">
40-
<input type="submit" value="Submit" *!*onclick="alert('click')"*/!*>
40+
<form onsubmit="alert('submit!');return false">
41+
<input type="text" size="30" value="Установите фокус здесь и нажмите Enter">
42+
<input type="submit" value="Отправить" *!*onclick="alert('click')"*/!*>
4143
</form>
4244
```
4345

4446
````
4547
46-
## Method: submit
48+
## Метод: submit
4749
48-
To submit a form to the server manually, we can call `form.submit()`.
50+
Чтобы отправить форму на сервер вручную, мы можем вызвать метод `form.submit()`.
4951
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.
52+
При этом событие `submit` не генерируется. Предполагается, что если программист вызывает метод `form.submit()`, то он уже выполнил всю соответствующую обработку.
5153
52-
Sometimes that's used to manually create and send a form, like this:
54+
Иногда это используют для генерации формы и отправки её вручную, например так:
5355
5456
```js run
5557
let form = document.createElement('form');
@@ -58,7 +60,7 @@ form.method = 'GET';
5860
5961
form.innerHTML = '<input name="q" value="test">';
6062
61-
// the form must be in the document to submit it
63+
// перед отправкой формы, её нужно вставить в документ
6264
document.body.append(form);
6365
6466
form.submit();

0 commit comments

Comments
 (0)