Customizing a widget "wrapper" on a form or schema

I don't know the best term for this, I'm talking about this template here plone.app.z3cform/plone/app/z3cform/templates/widget.pt at master · plone/plone.app.z3cform · GitHub. There's a dummy that will be replaced by the actual "widget", so this template is mostly in charge of the layout of the description/help, error messages, and wrapping it all with a div with some classes.

I wanted to use BS5 floating help labels for a field. The best I could come up with is to basically rebuild the entire wrapper stuff here in the widget, and then hide/unuse the original. I've also replaced "ploneform-widget-render" with a custom class on a site, but that customization applies to all forms on that site. But I really only want to customize this for one schema/form. Is that possible, or would I be better off just creating the entire form from scratch?

1 Like

I ended up having a custom edit page. Thankfully the ploneform macros have slots to make the customization minimal. The relevant section looks like this:

                 <tal:widgets repeat="widget python:view.widgets.values()">
                    <metal:field-slot define-slot="field">
                      <metal:field define-macro="field">
                        <tal:widget tal:replace="structure widget/@@floatinghelp-render-widget" />
                      </metal:field>
                    </metal:field-slot>
                  </tal:widgets>

This is good enough for my purpose here, but I could extend this to subclass the ploneform-macros view and make the widget render conditional on something defined on the form. This would allow you to use that form and define which fields you want floating in the view. I still think ideally you would set this on the schema, but that does not seem to be practical in the existing framework.