Skip to content

Commit

Permalink
Merge 56bfd3f into cf3e0b0
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz authored Dec 20, 2021
2 parents cf3e0b0 + 56bfd3f commit 74924a8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 50 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
4.3 (unreleased)
----------------

- Nothing changed yet.
- Update tests to ``lxml > 4.7``, thus requiring at least that version.
(`#107 <https://github.com/zopefoundation/z3c.form/issues/107>`_)


4.2 (2021-07-29)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def alltests():
'zope.pagetemplate >= 3.6.2',
],
test=[
'lxml >= 4.2',
'lxml >= 4.7.1',
'persistent',
'z3c.template >= 1.3',
'zc.sourcefactory',
Expand Down
36 changes: 19 additions & 17 deletions src/z3c/form/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -922,12 +922,12 @@ When the form renders, the label has now changed:
>>> addForm = PersonAddForm(root, TestRequest())
>>> addTemplate(addForm)
>>> addForm.update()
>>> print(testing.render(addForm, './/xmlns:div[2][@class="row"]'))
>>> print(testing.render(addForm, './/xmlns:div[2][@class="row"]')) # doctest: +NOPARSE_MARKUP
<div class="row">
<label for="form-widgets-name">Full Name</label>
<input class="text-widget required textline-field"
id="form-widgets-name" name="form.widgets.name" type="text" value="">
<input id="form-widgets-name" name="form.widgets.name" class="text-widget required textline-field" value="" type="text" />
</div>
...


Adding a "Cancel" button
Expand Down Expand Up @@ -966,15 +966,14 @@ After registering the new action manager,
the add form should display a cancel button:

>>> addForm.update()
>>> print(testing.render(addForm, './/xmlns:div[@class="action"]'))
>>> print(testing.render(addForm, './/xmlns:div[@class="action"]')) # doctest: +NOPARSE_MARKUP
<div class="action">
<input type="submit" id="form-buttons-add" name="form.buttons.add"
class="submit-widget button-field" value="Add" />
<input id="form-buttons-add" name="form.buttons.add" class="submit-widget button-field" value="Add" type="submit" />
</div>
<div class="action">
<input type="submit" id="form-buttons-cancel" name="form.buttons.cancel"
class="submit-widget button-field" value="Cancel" />
<input id="form-buttons-cancel" name="form.buttons.cancel" class="submit-widget button-field" value="Cancel" type="submit" />
</div>
...

But showing the button does not mean it does anything. So we also need a
custom action handler to handle the cancel action:
Expand Down Expand Up @@ -1159,8 +1158,9 @@ Let's now resubmit the form with valid data, so the data should be updated.
>>> editForm = PersonEditForm(root[u'srichter'], request)
>>> addTemplate(editForm)
>>> editForm.update()
>>> print(testing.render(editForm, './/xmlns:i'))
<i>Data successfully updated.</i>
>>> print(testing.render(editForm, './/xmlns:i')) # doctest: +NOPARSE_MARKUP
<i >Data successfully updated.</i>
...

>>> stephan = root[u'srichter']
>>> stephan.name
Expand Down Expand Up @@ -1222,8 +1222,9 @@ When submitting the form without any changes, the form will tell you so.
>>> editForm = PersonEditForm(root[u'srichter'], request)
>>> addTemplate(editForm)
>>> editForm.update()
>>> print(testing.render(editForm, './/xmlns:i'))
<i>No changes were applied.</i>
>>> print(testing.render(editForm, './/xmlns:i')) # doctest: +NOPARSE_MARKUP
<i >No changes were applied.</i>
...


Changing Status Messages
Expand All @@ -1247,8 +1248,9 @@ Let's now change the ``noChangesMessage``:

>>> editForm.noChangesMessage = u'No changes were detected in the form data.'
>>> editForm.update()
>>> print(testing.render(editForm, './/xmlns:i'))
<i>No changes were detected in the form data.</i>
>>> print(testing.render(editForm, './/xmlns:i')) # doctest: +NOPARSE_MARKUP
<i >No changes were detected in the form data.</i>
...

When even more flexibility is required within a project, one could also
implement these messages as properties looking up an attribute value. However,
Expand Down Expand Up @@ -1785,11 +1787,11 @@ The button will be available when context is not empty.
>>> myForm = SequenceForm(context, request)
>>> myForm.update()
>>> addTemplate(myForm)
>>> print(testing.render(myForm, './/xmlns:div[@class="action"]'))
>>> print(testing.render(myForm, './/xmlns:div[@class="action"]')) # doctest: +NOPARSE_MARKUP
<div class="action">
<input type="submit" id="form-buttons-empty" name="form.buttons.empty"
class="submit-widget button-field" value="Empty" />
<input id="form-buttons-empty" name="form.buttons.empty" class="submit-widget button-field" value="Empty" type="submit" />
</div>
...

The button will not be available when the context is empty.

Expand Down
78 changes: 47 additions & 31 deletions src/z3c/form/group.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,17 @@ Let's now submit the form, but forgetting to enter the address:

>>> add = RegistrationAddForm(None, request)
>>> add.update()
>>> print(testing.render(add, './/xmlns:i'))
<i>There were some errors.</i>
>>> print(testing.render(add, './/xmlns:i')) # doctest: +NOPARSE_MARKUP
<i >There were some errors.</i>
...

>>> print(testing.render(add, './/xmlns:fieldset[1]/xmlns:ul'))
<ul>
>>> print(testing.render(add, './/xmlns:fieldset[1]/xmlns:ul')) # doctest: +NOPARSE_MARKUP
<ul >
<li>
Address: <div class="error">Required input is missing.</div>
</li>
</ul>
...

As you can see, the template is clever enough to just report the errors at the
top of the form, but still report the actual problem within the group.
Expand All @@ -233,29 +235,33 @@ So what happens, if errors happen inside and outside a group?

>>> add = RegistrationAddForm(None, request)
>>> add.update()
>>> print(testing.render(add, './/xmlns:i'))
<i>There were some errors.</i>
>>> print(testing.render(add, './/xmlns:i')) # doctest: +NOPARSE_MARKUP
<i >There were some errors.</i>
...

>>> print(testing.render(add, './/xmlns:ul'))
<ul>
>>> print(testing.render(add, './/xmlns:ul')) # doctest: +NOPARSE_MARKUP
<ul >
<li>
Last Name:
<div class="error">Required input is missing.</div>
</li>
</ul>
<ul>
...
<ul >
<li>
Address:
<div class="error">Required input is missing.</div>
</li>
</ul>
...

>>> print(testing.render(add, './/xmlns:fieldset[1]/xmlns:ul'))
<ul>
>>> print(testing.render(add, './/xmlns:fieldset[1]/xmlns:ul')) # doctest: +NOPARSE_MARKUP
<ul >
<li>
Address: <div class="error">Required input is missing.</div>
</li>
</ul>
...

Let's now successfully complete the add form.

Expand Down Expand Up @@ -393,23 +399,26 @@ The behavior when an error occurs is identical to that of the add form:

>>> edit = RegistrationEditForm(reg, request)
>>> edit.update()
>>> print(testing.render(edit, './/xmlns:i'))
<i>There were some errors.</i>
>>> print(testing.render(edit, './/xmlns:i')) # doctest: +NOPARSE_MARKUP
<i >There were some errors.</i>
...

>>> print(testing.render(edit, './/xmlns:ul'))
<ul>
>>> print(testing.render(edit, './/xmlns:ul')) # doctest: +NOPARSE_MARKUP
<ul >
<li>
Address:
<div class="error">Required input is missing.</div>
</li>
</ul>
...

>>> print(testing.render(edit, './/xmlns:fieldset/xmlns:ul'))
<ul>
>>> print(testing.render(edit, './/xmlns:fieldset/xmlns:ul')) # doctest: +NOPARSE_MARKUP
<ul >
<li>
Address: <div class="error">Required input is missing.</div>
</li>
</ul>
...

When an edit form with groups is successfully committed, a detailed
object-modified event is sent out telling the system about the changes.
Expand Down Expand Up @@ -441,8 +450,9 @@ Let's now complete the form successfully:

The success message will be shown on the form, ...

>>> print(testing.render(edit, './/xmlns:i'))
<i>Data successfully updated.</i>
>>> print(testing.render(edit, './/xmlns:i')) # doctest: +NOPARSE_MARKUP
<i >Data successfully updated.</i>
...

and the data are correctly updated:

Expand Down Expand Up @@ -727,8 +737,9 @@ Richter gave his BMW to Paul Carduner because he is such a nice guy.

We'll see if everything worked on the form side.

>>> print(testing.render(edit, './/xmlns:i'))
<i>Data successfully updated.</i>
>>> print(testing.render(edit, './/xmlns:i')) # doctest: +NOPARSE_MARKUP
<i >Data successfully updated.</i>
...

Now the owner object should have updated fields.

Expand Down Expand Up @@ -806,8 +817,9 @@ Richter gave his BMW to Paul Carduner because he is such a nice guy.

We'll see if everything worked on the form side.

>>> print(testing.render(edit, './/xmlns:i'))
<i>Data successfully updated.</i>
>>> print(testing.render(edit, './/xmlns:i')) # doctest: +NOPARSE_MARKUP
<i >Data successfully updated.</i>
...

Now the owner object should have updated fields.

Expand Down Expand Up @@ -845,11 +857,12 @@ invalid object for the test missing input errors:
>>> edit = RegistrationEditForm(reg, request)
>>> edit.update()
>>> data, errors = edit.extractData()
>>> print(testing.render(edit, './/xmlns:i'))
>>> print(testing.render(edit, './/xmlns:i')) # doctest: +NOPARSE_MARKUP
<i >There were some errors.</i>
...

>>> print(testing.render(edit, './/xmlns:fieldset/xmlns:ul'))
<ul>
>>> print(testing.render(edit, './/xmlns:fieldset/xmlns:ul')) # doctest: +NOPARSE_MARKUP
<ul >
<li>
License:
<div class="error">Required input is missing.</div>
Expand All @@ -871,7 +884,8 @@ invalid object for the test missing input errors:
<div class="error">Required input is missing.</div>
</li>
</ul>
<ul>
...
<ul >
<li>
First Name:
<div class="error">Required input is missing.</div>
Expand All @@ -881,7 +895,7 @@ invalid object for the test missing input errors:
<div class="error">Required input is missing.</div>
</li>
</ul>

...

Group instance in nested group
------------------------------
Expand Down Expand Up @@ -1002,16 +1016,18 @@ Now test the error handling if just one missing value is given in a group:

>>> edit.update()
>>> data, errors = edit.extractData()
>>> print(testing.render(edit, './/xmlns:i'))
>>> print(testing.render(edit, './/xmlns:i')) # doctest: +NOPARSE_MARKUP
<i >There were some errors.</i>
...

>>> print(testing.render(edit, './/xmlns:fieldset/xmlns:ul'))
<ul>
>>> print(testing.render(edit, './/xmlns:fieldset/xmlns:ul')) # doctest: +NOPARSE_MARKUP
<ul >
<li>
Last Name:
<div class="error">Required input is missing.</div>
</li>
</ul>
...

Just check whether we fully support the interface:

Expand Down

0 comments on commit 74924a8

Please sign in to comment.