doc/book/en/devweb/edition/dissection.rst
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 24 Oct 2012 12:08:21 +0200
branchstable
changeset 8582 b0e086f451b7
parent 7643 f3e3892fc7e3
child 10222 75d6096216d7
permissions -rw-r--r--
prepare 3.15.5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5474
diff changeset
     1
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5474
diff changeset
     2
.. _form_dissection:
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     3
7643
f3e3892fc7e3 [book, form] include complete example of self-posted form with custom field/widget + minor other changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7635
diff changeset
     4
Dissection of an entity form
f3e3892fc7e3 [book, form] include complete example of self-posted form with custom field/widget + minor other changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7635
diff changeset
     5
----------------------------
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     6
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     7
This is done (again) with a vanilla instance of the `tracker`_
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     8
cube. We will populate the database with a bunch of entities and see
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     9
what kind of job the automatic entity form does.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    10
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    11
.. _`tracker`: http://www.cubicweb.org/project/cubicweb-tracker
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    12
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    13
Populating the database
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    14
~~~~~~~~~~~~~~~~~~~~~~~
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    15
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    16
We should start by setting up a bit of context: a project with two
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    17
unpublished versions, and a ticket linked to the project and the first
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    18
version.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    19
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    20
.. sourcecode:: python
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    21
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    22
 >>> p = rql('INSERT Project P: P name "cubicweb"')
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    23
 >>> for num in ('0.1.0', '0.2.0'):
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    24
 ...  rql('INSERT Version V: V num "%s", V version_of P WHERE P eid %%(p)s' % num, {'p': p[0][0]})
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    25
 ...
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    26
 <resultset 'INSERT Version V: V num "0.1.0", V version_of P WHERE P eid %(p)s' (1 rows): [765L] (('Version',))>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    27
 <resultset 'INSERT Version V: V num "0.2.0", V version_of P WHERE P eid %(p)s' (1 rows): [766L] (('Version',))>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    28
 >>> t = rql('INSERT Ticket T: T title "let us write more doc", T done_in V, '
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    29
             'T concerns P WHERE V num "0.1.0"', P eid %(p)s', {'p': p[0][0]})
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    30
 >>> commit()
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    31
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    32
Now let's see what the edition form builds for us.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    33
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    34
.. sourcecode:: python
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    35
7635
7dce83bc2df1 [book, forms] talk about cnx.use_web_compatible_request instead of custom monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5475
diff changeset
    36
 >>> cnx.use_web_compatible_requests('http://fakeurl.com')
7dce83bc2df1 [book, forms] talk about cnx.use_web_compatible_request instead of custom monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5475
diff changeset
    37
 >>> req = cnx.request()
7dce83bc2df1 [book, forms] talk about cnx.use_web_compatible_request instead of custom monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5475
diff changeset
    38
 >>> form = req.vreg['forms'].select('edition', req, rset=rql('Ticket T'))
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    39
 >>> html = form.render()
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    40
7635
7dce83bc2df1 [book, forms] talk about cnx.use_web_compatible_request instead of custom monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5475
diff changeset
    41
.. note::
7dce83bc2df1 [book, forms] talk about cnx.use_web_compatible_request instead of custom monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5475
diff changeset
    42
7dce83bc2df1 [book, forms] talk about cnx.use_web_compatible_request instead of custom monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5475
diff changeset
    43
  In order to play interactively with web side application objects, we have to
7dce83bc2df1 [book, forms] talk about cnx.use_web_compatible_request instead of custom monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5475
diff changeset
    44
  cheat a bit to have request object that will looks like HTTP request object, by
7dce83bc2df1 [book, forms] talk about cnx.use_web_compatible_request instead of custom monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5475
diff changeset
    45
  calling :meth:`use_web_compatible_requests()` on the connection.
7dce83bc2df1 [book, forms] talk about cnx.use_web_compatible_request instead of custom monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5475
diff changeset
    46
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    47
This creates an automatic entity form. The ``.render()`` call yields
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    48
an html (unicode) string. The html output is shown below (with
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    49
internal fieldset omitted).
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    50
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    51
Looking at the html output
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    52
~~~~~~~~~~~~~~~~~~~~~~~~~~
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    53
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    54
The form enveloppe
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    55
''''''''''''''''''
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    56
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    57
.. sourcecode:: html
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    58
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    59
 <div class="iformTitle"><span>main informations</span></div>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    60
 <div class="formBody">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    61
  <form action="http://crater:9999/validateform" method="post" enctype="application/x-www-form-urlencoded"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    62
        id="entityForm" onsubmit="return freezeFormButtons(&#39;entityForm&#39;);"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    63
        class="entityForm" cubicweb:target="eformframe">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    64
    <div id="progress">validating...</div>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    65
    <fieldset>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    66
      <input name="__form_id" type="hidden" value="edition" />
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    67
      <input name="__errorurl" type="hidden" value="http://perdu.com#entityForm" />
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    68
      <input name="__domid" type="hidden" value="entityForm" />
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    69
      <input name="__type:763" type="hidden" value="Ticket" />
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    70
      <input name="eid" type="hidden" value="763" />
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    71
      <input name="__maineid" type="hidden" value="763" />
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    72
      <input name="_cw_edited_fields:763" type="hidden"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    73
             value="concerns-subject,done_in-subject,priority-subject,type-subject,title-subject,description-subject,__type,_cw_generic_field" />
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    74
      ...
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    75
    </fieldset>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    76
   </form>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    77
 </div>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    78
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    79
The main fieldset encloses a set of hidden fields containing various
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    80
metadata, that will be used by the `edit controller` to process it
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    81
back correctly.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    82
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    83
The `freezeFormButtons(...)` javascript callback defined on the
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5474
diff changeset
    84
``onlick`` event of the form element prevents accidental multiple
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    85
clicks in a row.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    86
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
    87
The ``action`` of the form is mapped to the ``validateform`` controller
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    88
(situated in :mod:`cubicweb.web.views.basecontrollers`).
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    89
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
    90
A full explanation of the validation loop is given in
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
    91
:ref:`validation_process`.
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
    92
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5474
diff changeset
    93
.. _attributes_section:
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5474
diff changeset
    94
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    95
The attributes section
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    96
''''''''''''''''''''''
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    97
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    98
We can have a look at some of the inner nodes of the form. Some fields
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    99
are omitted as they are redundant for our purposes.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   100
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   101
.. sourcecode:: html
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   102
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   103
      <fieldset class="default">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   104
        <table class="attributeForm">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   105
          <tr class="title_subject_row">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   106
            <th class="labelCol"><label class="required" for="title-subject:763">title</label></th>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   107
            <td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   108
              <input id="title-subject:763" maxlength="128" name="title-subject:763" size="45"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   109
                     tabindex="1" type="text" value="let us write more doc" />
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   110
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   111
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   112
          ... (description field omitted) ...
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   113
          <tr class="priority_subject_row">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   114
            <th class="labelCol"><label class="required" for="priority-subject:763">priority</label></th>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   115
            <td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   116
              <select id="priority-subject:763" name="priority-subject:763" size="1" tabindex="4">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   117
                <option value="important">important</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   118
                <option selected="selected" value="normal">normal</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   119
                <option value="minor">minor</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   120
              </select>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   121
              <div class="helper">importance</div>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   122
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   123
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   124
          ... (type field omitted) ...
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   125
          <tr class="concerns_subject_row">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   126
            <th class="labelCol"><label class="required" for="concerns-subject:763">concerns</label></th>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   127
            <td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   128
              <select id="concerns-subject:763" name="concerns-subject:763" size="1" tabindex="6">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   129
                <option selected="selected" value="760">Foo</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   130
              </select>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   131
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   132
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   133
          <tr class="done_in_subject_row">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   134
            <th class="labelCol"><label for="done_in-subject:763">done in</label></th>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   135
            <td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   136
              <select id="done_in-subject:763" name="done_in-subject:763" size="1" tabindex="7">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   137
                <option value="__cubicweb_internal_field__"></option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   138
                <option selected="selected" value="761">Foo 0.1.0</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   139
                <option value="762">Foo 0.2.0</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   140
              </select>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   141
              <div class="helper">version in which this ticket will be / has been  done</div>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   142
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   143
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   144
        </table>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   145
      </fieldset>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   146
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   147
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   148
Note that the whole form layout has been computed by the form
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   149
renderer. It is the renderer which produces the table
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   150
structure. Otherwise, the fields html structure is emitted by their
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   151
associated widget.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   152
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   153
While it is called the `attributes` section of the form, it actually
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   154
contains attributes and *mandatory relations*. For each field, we
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   155
observe:
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   156
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   157
* a dedicated row with a specific class, such as ``title_subject_row``
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   158
  (responsability of the form renderer)
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   159
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   160
* an html widget (input, select, ...) with:
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   161
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   162
  * an id built from the ``rtype-role:eid`` pattern
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   163
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   164
  * a name built from the same pattern
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   165
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   166
  * possible values or preselected options
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   167
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   168
The relations section
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   169
'''''''''''''''''''''
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   170
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   171
.. sourcecode:: html
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   172
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   173
      <fieldset class="This ticket :">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   174
        <legend>This ticket :</legend>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   175
        <table class="attributeForm">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   176
          <tr class="_cw_generic_field_None_row">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   177
            <td colspan="2">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   178
              <table id="relatedEntities">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   179
                <tr><th>&#160;</th><td>&#160;</td></tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   180
                <tr id="relationSelectorRow_763" class="separator">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   181
                  <th class="labelCol">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   182
                    <select id="relationSelector_763" tabindex="8"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   183
                            onchange="javascript:showMatchingSelect(this.options[this.selectedIndex].value,763);">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   184
                      <option value="">select a relation</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   185
                      <option value="appeared_in_subject">appeared in</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   186
                      <option value="custom_workflow_subject">custom workflow</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   187
                      <option value="depends_on_object">dependency of</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   188
                      <option value="depends_on_subject">depends on</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   189
                      <option value="identical_to_subject">identical to</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   190
                      <option value="see_also_subject">see also</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   191
                    </select>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   192
                  </th>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   193
                  <td id="unrelatedDivs_763"></td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   194
                </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   195
              </table>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   196
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   197
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   198
        </table>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   199
      </fieldset>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   200
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   201
The optional relations are grouped into a drop-down combo
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   202
box. Selection of an item triggers a javascript function which will:
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   203
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   204
* show already related entities in the div of id `relatedentities`
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   205
  using a two-colown layout, with an action to allow deletion of
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   206
  individual relations (there are none in this example)
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   207
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   208
* provide a relation selector in the div of id `relationSelector_EID`
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   209
  to allow the user to set up relations and trigger dynamic action on
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   210
  the last div
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   211
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   212
* fill the div of id `unrelatedDivs_EID` with a dynamically computed
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   213
  selection widget allowing direct selection of an unrelated (but
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   214
  relatable) entity or a switch towards the `search mode` of
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   215
  |cubicweb| which allows full browsing and selection of an entity
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   216
  using a dedicated action situated in the left column boxes.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   217
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   218
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   219
The buttons zone
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   220
''''''''''''''''
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   221
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   222
Finally comes the buttons zone.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   223
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   224
.. sourcecode:: html
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   225
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   226
      <table width="100%">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   227
        <tbody>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   228
          <tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   229
            <td align="center">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   230
              <button class="validateButton" tabindex="9" type="submit" value="validate">
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   231
                <img alt="OK_ICON" src="http://myapp/datafd8b5d92771209ede1018a8d5da46a37/ok.png" />
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   232
                validate
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   233
              </button>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   234
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   235
            <td style="align: right; width: 50%;">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   236
              <button class="validateButton"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   237
                      onclick="postForm(&#39;__action_apply&#39;, &#39;button_apply&#39;, &#39;entityForm&#39;)"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   238
                      tabindex="10" type="button" value="apply">
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   239
                <img alt="APPLY_ICON" src="http://myapp/datafd8b5d92771209ede1018a8d5da46a37/plus.png" />
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   240
                apply
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   241
              </button>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   242
              <button class="validateButton"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   243
                      onclick="postForm(&#39;__action_cancel&#39;, &#39;button_cancel&#39;, &#39;entityForm&#39;)"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   244
                      tabindex="11" type="button" value="cancel">
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   245
                <img alt="CANCEL_ICON" src="http://myapp/datafd8b5d92771209ede1018a8d5da46a37/cancel.png" />
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   246
                cancel
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   247
              </button>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   248
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   249
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   250
        </tbody>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   251
      </table>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   252
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   253
The most notable artifacts here are the ``postForm(...)`` calls
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   254
defined on click events on these buttons. This function basically
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   255
submits the form.
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   256
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5474
diff changeset
   257
.. _validation_process:
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   258
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   259
The form validation process
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   260
---------------------------
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   261
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   262
Preparation
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   263
~~~~~~~~~~~
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   264
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   265
After the (html) document is loaded, the ``setFormsTarget`` javascript
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   266
function dynamically transforms the DOM as follows. For all forms of
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   267
the DOM, it:
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   268
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   269
* sets the ``target`` attribute where there is a ``cubicweb:target``
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   270
  attribute (with the same value)
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   271
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   272
* appends an empty `IFRAME` element at the end
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   273
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   274
Let us have a look again at the form element. We have omitted some
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   275
irrelevant attributes.
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   276
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   277
.. sourcecode::html
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   278
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   279
  <form action="http://crater:9999/validateform" method="post"
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   280
        enctype="application/x-www-form-urlencoded"
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   281
        id="entityForm" cubicweb:target="eformframe"
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   282
        target="eformframe">
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   283
  ...
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   284
  </form>
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   285
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   286
Validation loop
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   287
~~~~~~~~~~~~~~~
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   288
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   289
On form submission, the form.action is invoked. Basically, the
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   290
``validateform`` controller is called and its output lands in the
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   291
specified ``target``, the iframe that was previously prepared.
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   292
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   293
Hence, the main page is not replaced, only the iframe contents. The
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   294
``validateform`` controller only outputs a tiny javascript fragment
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   295
which is then immediately executed.
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   296
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   297
.. sourcecode:: html
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   298
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   299
 <iframe width="0px" height="0px" name="eformframe" id="eformframe" src="javascript: void(0)">
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   300
   <script type="text/javascript">
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   301
     window.parent.handleFormValidationResponse('entityForm', null, null,
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   302
                                                [false, [2164, {"name-subject": "required field"}], null],
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   303
                                                null);
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   304
   </script>
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   305
 </iframe>
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   306
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   307
The ``window.parent`` part ensures the javascript function is called
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   308
on the right context (that is: the form element). We will describe its
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   309
parameters:
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   310
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   311
* first comes the form id (`entityForm`)
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   312
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   313
* then two optional callbacks for the success and failure case
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   314
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   315
* an array containing:
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   316
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   317
  * a boolean which indicates status (success or failure), and then, on error:
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   318
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   319
    * an array structured as ``[eid, {'rtype-role': 'error msg'}, ...]``
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   320
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   321
  * on success:
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   322
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   323
    * an url (string) representing the next thing to jump to
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   324
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   325
Given the array structure described above, it is quite simple to
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   326
manipulate the DOM to show the errors at appropriate places.
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   327
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   328
Explanation
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   329
~~~~~~~~~~~
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   330
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   331
This mecanism may seem a bit overcomplicated but we have to deal with
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   332
two realities:
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   333
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   334
* in the (strict) XHTML world, there are no iframes (hence the dynamic
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   335
  inclusion, tolerated by Firefox)
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   336
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   337
* no (or not all) browser(s) support file input field handling through
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   338
  ajax.