Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dependencies and css_class work in fieldsets as well. #389

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Changelog
4.1.2 (unreleased)
------------------

- Make dependencies and css_class work in fieldsets as well.
Note that this overrides ``widget.pt`` from ``plone.app.z3cform`` for *all* forms.
Should be okay: they are currently very similar.
[maurits]

- Fix xml schema editor for fields and actions.
Fixes `issue 366 <https://github.com/collective/collective.easyform/issues/366>`_.
[maurits]
Expand Down
5 changes: 3 additions & 2 deletions src/collective/easyform/browser/widget.pt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
error_class python:error and ' error' or '';
empty_values python: (None, '', [], ('', '', '', '00', '00', ''), ('', '', ''));
empty_class python: (widget.value in empty_values) and ' empty' or '';
dependencies view/@@dependencies;
dependencies view/@@dependencies|nothing;
pat_depends_class python: dependencies and 'pat-depends'"
data-pat-inlinevalidation='{"type":"z3c.form"}'
data-pat-depends="${dependencies}"
id="formfield-${python:widget.id}"
class="field fieldname-${python:widget.name} widget-mode-${python:widget.mode}${error_class}${empty_class} ${python:getattr(widget, 'wrapper_css_class', '') or ''} ${view/@@css_class} ${pat_depends_class}"
class="field fieldname-${python:widget.name} widget-mode-${python:widget.mode}${error_class}${empty_class} ${python:getattr(widget, 'wrapper_css_class', '') or ''} ${view/@@css_class|nothing} ${pat_depends_class}"
data-fieldname="${widget/name}">

<label for="${python:widget.id}"
class="form-label"
tal:condition="python: widget.mode == 'input' and widget.label">
Expand Down
22 changes: 22 additions & 0 deletions src/collective/easyform/browser/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collective.easyform.interfaces import ILabelWidget
from collective.easyform.interfaces import IRenderWidget
from collective.easyform.interfaces import IRichLabelWidget
from plone.app.z3cform.views import RenderWidget as PloneRenderWidget
from Products.Five.browser import BrowserView
from Products.Five.browser.metaconfigure import ViewMixinForTemplates
from z3c.form import interfaces
Expand All @@ -18,6 +19,11 @@
from zope.publisher.interfaces.browser import IBrowserView
from zope.schema.interfaces import IField

import logging


logger = logging.getLogger(__name__)


@implementer_only(ILabelWidget)
class LabelWidget(widget.HTMLFormElement, Widget):
Expand Down Expand Up @@ -106,3 +112,19 @@ def __call__(self):
if not css_class:
return dflt
return css_class


PloneRenderWidget.index = ViewPageTemplateFile("widget.pt")
logger.info("Patched plone.app.z3cform.views.RenderWidget to use our widget.pt.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me uneasy. If a project has also customized this template using z3c.jbot, which one wins?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes me uneasy too.
One way to solve this, would be to actually take over the widget template from easyform in plone.app.z3cform. Should be okay. But definitely not now, a few days before Plone 6 final. That makes me far more uneasy. ;-)



@adapter(PloneRenderWidget, Interface)
@implementer(IBrowserView)
class PloneWidgetDependencyView(WidgetDependencyView):
pass


@adapter(PloneRenderWidget, Interface)
@implementer(IBrowserView)
class PloneWidgetCssClassView(WidgetCssClassView):
pass
8 changes: 8 additions & 0 deletions src/collective/easyform/browser/widgets.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,19 @@
factory=".widgets.WidgetDependencyView"
name="dependencies"
/>
<adapter
factory=".widgets.PloneWidgetDependencyView"
name="dependencies"
/>

<adapter
factory=".widgets.WidgetCssClassView"
name="css_class"
/>
<adapter
factory=".widgets.PloneWidgetCssClassView"
name="css_class"
/>

<!-- add CheckboxFieldWidget for ISet to enable checkbox list -->
<adapter
Expand Down