AJAX form submission (inline success)

  • Mapping

Captured

None

Code (show in context)

    @view_config(renderer='templates/form.pt', name='ajaxform')
    @demonstrate('AJAX form submission (inline success)')
    def ajaxform(self):
        class Mapping(colander.Schema):
            name = colander.SchemaNode(
                colander.String(),
                description='Content name')
            date = colander.SchemaNode(
                colander.Date(),
                widget=deform.widget.DatePartsWidget(),
                description='Content date')
        class Schema(colander.Schema):
            number = colander.SchemaNode(
                colander.Integer())
            mapping = Mapping()
            richtext = colander.SchemaNode(
                colander.String(),
                widget=deform.widget.RichTextWidget())
        schema = Schema()
        def succeed():
            return Response('<div id="thanks">Thanks!</div>')
        form = deform.Form(schema, buttons=('submit',), use_ajax=True)
        return self.render_form(form, success=succeed)