Plone/form.SchemaForm - How can I reposition a button in a SchemaForm?

时光毁灭记忆、已成空白 提交于 2019-12-24 06:00:01

问题


I have an interface class, an class mapped to a back end database, and a form.SchemaForm class.

Here is my interface.

class IAsset(form.Schema):
    """Interface class of an asset
    """
    ...
    Options = schema.Text.....

    Parent = schema.Int(title=u"Parent",
                        required=False
                       )

    Status = schema.Choice.....  

I don't think the ORM class is of any instance, but here is a bit of my SchemaForm.

class AddAsset(form.SchemaForm):
    grok.name('add-asset')
    grok.require('zope2.View')
    grok.context(ISiteRoot)

    schema = IAsset
    ignoreContext = True
    ....

    @button.buttonAndHandler(u"Select Parent Asset")
        #open parent form to select a parent asset

I would like to reposition the button to be below parent instead of at the bottom of the form. Is this possible or would I have to create some sort of template file?


回答1:


If you want to repostion your button you have to use your own template.

In z3c.form you can do this by following this example.

from z3c.form import form


class MyForm(form.Form):

    template = ViewPageTemplateFile('templates/custom_template.pt')

In the template you can access all parts of the form manually.

In your case you could simple render the hole form and but your part into the formtop slot.

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      i18n:domain="plone"
      metal:use-macro="context/main_template/macros/master">

  <metal:block fill-slot="top_slot"
           tal:define="dummy python:request.set('disable_border',1);
                       dummy python:request.set('disable_plone.leftcolumn', 1);
                       dummy python:request.set('disable_plone.rightcolumn', 1);
                       " />


    <metal:block fill-slot="main">

        <metal:form use-macro="context/@@ploneform-macros/form">
            <metal:topslot fill-slot="formtop">
               <!-- Implement your action here. -->
            </metal:topslot
        </metal:form>


    </<metal:block>

</html>

Usually the form defined in plone.app.z3cform is used. Check this https://github.com/plone/plone.app.z3cform/blob/36586431ed8e067c761e33c725758ce2c1b460f8/plone/app/z3cform/templates/macros.pt for detailed information.



来源:https://stackoverflow.com/questions/27315829/plone-form-schemaform-how-can-i-reposition-a-button-in-a-schemaform

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!