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

The conditional fields have now widgets that can be customized as needed #761

Merged
merged 1 commit into from
Sep 11, 2024
Merged
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: 4 additions & 1 deletion docs/changes.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Changelog
=========

16.2.2 (unreleased)
16.3.0 (unreleased)
-------------------

- The conditional fields have now widgets that can be customized as needed
[ale-rt]

- Update prototype from commit 317e62820b35678055240ca911d24a3b45db44d6
Ref: scrum-2333
[reinhardt]
Expand Down
2 changes: 2 additions & 0 deletions src/euphorie/content/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
/>

<adapter factory=".dependency.ConditionalFieldValidator" />
<adapter factory=".dependency.ConditionalTextFieldWidget" />
<adapter factory=".dependency.ConditionalHtmlTextFieldWidget" />

<adapter
factory=".help.SearchableTextIndexer"
Expand Down
68 changes: 67 additions & 1 deletion src/euphorie/content/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,93 @@

from euphorie.content.user import BaseValidator
from euphorie.htmllaundry.z3cform import HtmlText
from euphorie.htmllaundry.z3cform import IHtmlText
from plonetheme.nuplone.z3cform.directives import Dependency
from plonetheme.nuplone.z3cform.interfaces import INuPloneFormLayer
from z3c.form.browser.text import TextWidget
from z3c.form.browser.textarea import TextAreaWidget
from z3c.form.interfaces import IFieldWidget
from z3c.form.interfaces import IForm
from z3c.form.interfaces import ITextAreaWidget
from z3c.form.interfaces import ITextWidget
from z3c.form.interfaces import IValidator
from z3c.form.widget import FieldWidget
from zope import schema
from zope.component import adapter
from zope.interface import implementer
from zope.interface import implementer_only
from zope.interface import Interface
from zope.schema.interfaces import IFromUnicode


class ConditionalField:
"""Marker class for conditional fields."""
"""Marker class for conditional fields.

FIXME: this class is used to register a custom validator adapter
for the copnditional text input and textarea fields.

We should avoid using this mixin class and
use a proper common interface instead.
"""


# Interfaces
class IConditionalTextLine(IFromUnicode):
"""A Text line that is only shown under certain conditions."""


class IConditionalHtmlText(IHtmlText):
"""HTML Text field that is only shown under certain conditions."""


class IConditionalTextWidget(ITextWidget):
"""Text widget that is only shown under certain conditions."""


class IConditionalHtmlTextWidget(ITextAreaWidget):
"""Text area widget that is only shown under certain conditions."""


# Fields
@implementer(IConditionalTextLine)
class ConditionalTextLine(schema.TextLine, ConditionalField):
"""A Text line that is only shown under certain conditions."""


@implementer(IConditionalHtmlText)
class ConditionalHtmlText(HtmlText, ConditionalField):
"""HTML Text field that is only shown under certain conditions."""


# Widgets
@implementer_only(IConditionalTextWidget)
class ConditionalTextWidget(TextWidget):
"""Text widget that is only shown under certain conditions."""

klass = "conditional-text-widget"


@implementer_only(IConditionalHtmlTextWidget)
class ConditionalHtmlTextWidget(TextAreaWidget):
"""Text area widget that is only shown under certain conditions."""

klass = "conditional-textarea-widget"


# Field widget factories
@adapter(IConditionalTextLine, INuPloneFormLayer)
@implementer(IFieldWidget)
def ConditionalTextFieldWidget(field, request):
return FieldWidget(field, ConditionalTextWidget(request))


@adapter(IConditionalHtmlText, INuPloneFormLayer)
@implementer(IFieldWidget)
def ConditionalHtmlTextFieldWidget(field, request):
return FieldWidget(field, ConditionalHtmlText(request))


# Validator
@implementer(IValidator)
@adapter(Interface, Interface, IForm, ConditionalField, Interface)
class ConditionalFieldValidator(BaseValidator):
Expand Down
Loading