Skip to content

Commit

Permalink
гл.7 перевод 8%
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrbonit committed Jun 25, 2016
1 parent f41f79c commit 2fc8465
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions sources/43-web2py-russian-translation-in-progress/07.markmin
Expand Up @@ -171,15 +171,14 @@ form.process(...,dbio=False).accepted

#### Условные поля

There are times when you only want a field to show up if a condition is met. For example, consider
the following model:
Есть моменты, когда вы хотите отобразить поле, если условие выполнено. Например, рассмотрим следующую модель:

``
db.define_table('purchase', Field('have_coupon','boolean'),Field('coupon_code'))
``

You want to display the field ``coupon_code`` if and only if the ``have_coupon`` field is checked.
This can be done in JavaScript. web2py can help you by genering that JavaScript for you. You just need to declare that the field is conditional to an expression using the field ``show_if`` attribute:
Вы хотите, чтобы отобразить поле ``coupon_code`` тогда и только тогда, когда ``have_coupon`` поле проверено.
Это может быть сделано в JavaScript. web2py может помочь вам через genering, что JavaScript для вас. Вам просто нужно объявить, что поле является условным к выражению, используя атрибут поля ``show_if``:

``
def index():
Expand All @@ -188,11 +187,11 @@ def index():
return dict(form = form)
``

The value of ``show_if`` is a query and uses the same DAL syntax that you use for database queries. The difference is that this query not sent to the database but it is converted to JavaScript and sent to the browser where it is executed when the user edits the form.
Значение ``show_if`` является запросом и использует тот же синтаксис DAL, который используется для запросов к базе данных. Разница заключается в том, что этот запрос не отправляется в базу данных, но он преобразуется в JavaScript и отправляется в браузер, где он выполняется, когда пользователь изменяет форму.

#### Hidden fields
#### Скрытые поля

When the above form object is serialized by ``{{=form}}``, and because of the previous call to the ``accepts`` method, it now looks like this:
Когда вышеупомянутый объект формы сериализуется через ``{{=form}}``, и из-за предыдущего вызова к ``accepts`` методу, он теперь выглядит следующим образом:
``
<form enctype="multipart/form-data" action="" method="post">
your name:
Expand All @@ -203,10 +202,10 @@ your name:
</form>
``:code

Notice the presence of two hidden fields: "_formkey" and "_formname". Their presence is triggered by the call to ``accepts`` and they play two different and important roles:
- The hidden field called "_formkey" is a one-time token that web2py uses to prevent double submission of forms. The value of this key is generated when the form is serialized and stored in the ``session``. When the form is submitted this value must match, or else ``accepts`` returns ``False`` without errors as if the form was not submitted at all. This is because web2py cannot determine whether the form was submitted correctly.
- The hidden field called "_formname" is generated by web2py as a name for the form, but the name can be overridden. This field is necessary to allow pages that contain and process multiple forms. web2py distinguishes the different submitted forms by their names.
- Optional hidden fields specified as ``FORM(..,hidden=dict(...))``.
Обратите внимание на наличие двух скрытых полей: "_formkey" и "_formname". Их присутствие обусловлено вызовом ``accepts`` и они играют две разные и важные роли:
- Скрытое поле под названием "_formkey" является одноразовым токеном, которое web2py использует во избежание двойной подачи форм. Значение этого ключа генерируется, когда форма сериализуется и сохраняется в ``session``. Когда форма передается это значение должно совпадать, либо ``accepts`` возвращает ``False`` без ошибок, как если бы форма не была представлена на всех. Это происходит потому, что web2py не может определить, является ли форма правильно предоставленной.
- Скрытое поле, называемое "_formname" генерируется web2py как имя для формы, но имя может быть изменено. Это поле необходимо, чтобы разрешить страницы, которые содержат и обрабатывают несколько форм. web2py различает различные представленные формы по их именам.
- Необязательные скрытые поля, указанные как ``FORM(..,hidden=dict(...))``.

The role of these hidden fields and their usage in custom forms and pages with multiple forms is discussed in more detail later in the chapter.

Expand Down

0 comments on commit 2fc8465

Please sign in to comment.