@view_config(renderer="templates/popup_example.pt", name="popup")
@demonstrate("Popup and retail rendering")
def popup(self):
"""Render a page (``popup_example.pt``) that contains
a specially styled form (``modal.pt``).
.. note ::
Pop up form templates are NOT supplied with Deform core.
They are in the deformdemo package for demostration purposes.
You can copy them to your own project and configure
widget template paths.
popup_example.pt contains the page HTML template.
Javascript: The JavaScript logic to show and hide the pop up is
in ``poup_example.pt``.
We need to automatically open the pop up on a validation error.
Template registration: See ``deformdemo.main`` how we register a
template path ``custom_widgets`` where the custom form template lies.
See also :ref:`templates` in Deform documentation for more information.
Source code:
https://github.com/Pylons/deformdemo/blob/master/deformdemo/templates/popup_example.pt
https://github.com/Pylons/deformdemo/blob/master/deformdemo/custom_widgets/modal.pt
"""
class Schema(colander.Schema):
title = "Pop up example title"
# Override default form.pt for rendering <form>
widget = deform.widget.FormWidget(template="modal.pt")
name = colander.SchemaNode(
colander.String(), description="Enter your name (required)"
)
schema = Schema()
form = deform.Form(schema, buttons=("submit",))
# CSS is used in <button> opener and JS code
form.formid = "my-pop-up"
return self.render_form(form)