[Zope3-Users] Arranging widgets in a form / Limit size of input
fields
Maciej Wisniowski
maciej.wisniowski at coig.katowice.pl
Thu May 3 12:17:54 EDT 2007
> In my case, I have several forms with e.g. 10-15 fields, so this adds up and
> in the end the templates are quite complex. If there were some shortcut or
> macro which generates the above HTML-code, it would be a lot easier, perhaps
> there's a decent solution? If it would looke something like this, it would be
> much easier to manage:
>
> <span tal:content="view/widgets/foo/gen_html />
>
Isn't tal:repeat enough?? Something like:
<tal:block tal:repeat="widget view/widgets">
<div class="label">
<label for="field.name" title="The widget's hint"
tal:attributes="for widget; title widget/hint"
tal:content="widget/label">Label</label>
</div>
<div tal:condition="widget/error"
tal:content="structure widget/error">Error</div>
<div class="field">
<input tal:replace="structure widget" />
</div>
</tal:block>
If you need specific widgets order then you may use:
form.FormFields(interfaces.ISomeInterface).select('field1', 'field2',....)
Another possibility io define function in your view class like:
widgetTempl = ViewPageTemplateFile('widgetsection.pt')
def genWidgetHtml(self, widget):
return self.widgetTempl(widget=widget)
and create file widgetsection.pt with content like:
<tal:block tal:define="widget python: options.get('widget', None)">
<div class="label">
<label for="field.name" title="The widget's hint"
tal:attributes="for widget; title widget/hint"
tal:content="widget/label">Label</label>
</div>
<div tal:condition="widget/error"
tal:content="structure widget/error">Error</div>
<div class="field">
<input tal:replace="structure widget" />
</div>
</tal:block>
Then in your pageform.pt just call for every widget something like:
<div tal:replace="python: view.getWidgetHtml(view.widgets['foo']" />
Above code is from head so may be buggy or incomplete.
--
Maciej Wisniowski
More information about the Zope3-users
mailing list