doc/book/devweb/edition/dissection.rst
author Julien Cristau <julien.cristau@logilab.fr>
Fri, 05 Feb 2016 16:32:20 +0100
changeset 11095 02e88ca3bc23
parent 10491 c67bcee93248
child 11875 011730a4af73
permissions -rw-r--r--
[dataimport/test] fix test failures since 35b29f1eb37a The index name changed, so we need to follow suit.
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;);"
10434
8e04ab5582d9 [web/views/formrenderer] do not use `cubicweb:target` attribute on form (closes #5534074)
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 10222
diff changeset
    63
        class="entityForm" target="eformframe">
5464
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>
10434
8e04ab5582d9 [web/views/formrenderer] do not use `cubicweb:target` attribute on form (closes #5534074)
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 10222
diff changeset
    76
    <iframe width="0px" height="0px" name="eformframe" id="eformframe" src="javascript: void(0);"></iframe>
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    77
   </form>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    78
 </div>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    79
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    80
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
    81
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
    82
back correctly.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    83
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    84
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
    85
``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
    86
clicks in a row.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    87
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
    88
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
    89
(situated in :mod:`cubicweb.web.views.basecontrollers`).
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    90
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
    91
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
    92
:ref:`validation_process`.
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
    93
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5474
diff changeset
    94
.. _attributes_section:
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5474
diff changeset
    95
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    96
The attributes section
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
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    99
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
   100
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
   101
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   102
.. sourcecode:: html
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   103
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   104
      <fieldset class="default">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   105
        <table class="attributeForm">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   106
          <tr class="title_subject_row">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   107
            <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
   108
            <td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   109
              <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
   110
                     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
   111
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   112
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   113
          ... (description field omitted) ...
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   114
          <tr class="priority_subject_row">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   115
            <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
   116
            <td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   117
              <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
   118
                <option value="important">important</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   119
                <option selected="selected" value="normal">normal</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   120
                <option value="minor">minor</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   121
              </select>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   122
              <div class="helper">importance</div>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   123
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   124
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   125
          ... (type field omitted) ...
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   126
          <tr class="concerns_subject_row">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   127
            <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
   128
            <td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   129
              <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
   130
                <option selected="selected" value="760">Foo</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   131
              </select>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   132
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   133
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   134
          <tr class="done_in_subject_row">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   135
            <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
   136
            <td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   137
              <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
   138
                <option value="__cubicweb_internal_field__"></option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   139
                <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
   140
                <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
   141
              </select>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   142
              <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
   143
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   144
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   145
        </table>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   146
      </fieldset>
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
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   149
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
   150
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
   151
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
   152
associated widget.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   153
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   154
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
   155
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
   156
observe:
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   157
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   158
* 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
   159
  (responsability of the form renderer)
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   160
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   161
* an html widget (input, select, ...) with:
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   162
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   163
  * 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
   164
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   165
  * a name built from the same pattern
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   166
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   167
  * possible values or preselected options
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   168
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   169
The relations section
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
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   172
.. sourcecode:: html
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   173
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   174
      <fieldset class="This ticket :">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   175
        <legend>This ticket :</legend>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   176
        <table class="attributeForm">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   177
          <tr class="_cw_generic_field_None_row">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   178
            <td colspan="2">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   179
              <table id="relatedEntities">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   180
                <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
   181
                <tr id="relationSelectorRow_763" class="separator">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   182
                  <th class="labelCol">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   183
                    <select id="relationSelector_763" tabindex="8"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   184
                            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
   185
                      <option value="">select a relation</option>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   186
                      <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
   187
                      <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
   188
                      <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
   189
                      <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
   190
                      <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
   191
                      <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
   192
                    </select>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   193
                  </th>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   194
                  <td id="unrelatedDivs_763"></td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   195
                </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   196
              </table>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   197
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   198
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   199
        </table>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   200
      </fieldset>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   201
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   202
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
   203
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
   204
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   205
* 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
   206
  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
   207
  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
   208
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   209
* 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
   210
  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
   211
  the last div
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   212
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   213
* 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
   214
  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
   215
  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
   216
  |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
   217
  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
   218
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   219
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   220
The buttons zone
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
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   223
Finally comes the buttons zone.
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   224
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   225
.. sourcecode:: html
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   226
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   227
      <table width="100%">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   228
        <tbody>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   229
          <tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   230
            <td align="center">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   231
              <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
   232
                <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
   233
                validate
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   234
              </button>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   235
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   236
            <td style="align: right; width: 50%;">
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   237
              <button class="validateButton"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   238
                      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
   239
                      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
   240
                <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
   241
                apply
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   242
              </button>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   243
              <button class="validateButton"
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   244
                      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
   245
                      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
   246
                <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
   247
                cancel
5464
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   248
              </button>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   249
            </td>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   250
          </tr>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   251
        </tbody>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   252
      </table>
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   253
c6c9a80ad1dd [doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   254
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
   255
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
   256
submits the form.
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   257
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5474
diff changeset
   258
.. _validation_process:
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   259
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   260
The form validation process
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
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   263
Validation loop
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
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   266
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
   267
``validateform`` controller is called and its output lands in the
10434
8e04ab5582d9 [web/views/formrenderer] do not use `cubicweb:target` attribute on form (closes #5534074)
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 10222
diff changeset
   268
specified ``target``, an invisible ``<iframe>`` at the end of the
8e04ab5582d9 [web/views/formrenderer] do not use `cubicweb:target` attribute on form (closes #5534074)
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 10222
diff changeset
   269
form.
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   270
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   271
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
   272
``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
   273
which is then immediately executed.
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   274
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   275
.. sourcecode:: html
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   276
10434
8e04ab5582d9 [web/views/formrenderer] do not use `cubicweb:target` attribute on form (closes #5534074)
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 10222
diff changeset
   277
 <iframe width="0px" height="0px" name="eformframe" id="eformframe" src="javascript: void(0);">
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   278
   <script type="text/javascript">
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   279
     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
   280
                                                [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
   281
                                                null);
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   282
   </script>
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   283
 </iframe>
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   284
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   285
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
   286
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
   287
parameters:
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
* 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
   290
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   291
* 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
   292
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   293
* an array containing:
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   294
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   295
  * 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
   296
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   297
    * 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
   298
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   299
  * on success:
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   300
10222
75d6096216d7 [docstrings] fix project-wide English language mistake
Dimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
parents: 7643
diff changeset
   301
    * a url (string) representing the next thing to jump to
5474
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   302
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   303
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
   304
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
   305
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   306
Explanation
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   307
~~~~~~~~~~~
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   308
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   309
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
   310
two realities:
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   311
1fc46a6287a7 [doc/book] explain the form loop validation process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5464
diff changeset
   312
* 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
   313
  inclusion, tolerated by Firefox)
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
* 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
   316
  ajax.