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

Support for "readonly" and "hidden" visibility modes in ReferenceWidget #1466

Merged
merged 3 commits into from Nov 7, 2019

Conversation

xispa
Copy link
Member

@xispa xispa commented Nov 4, 2019

Description of the issue/feature this PR addresses

This Pull Request makes the reference widget to support the following visibility settings on "edit" mode: "invisible", "hidden" and "readonly".

Use case

We want the field "Client" to be displayed in read-only mode in Batch edit form when the folder of the context is from "Client" type, so the user cannot change the value:

  <!-- Visibility of Client field in Batch context -->
  <adapter
    factory=".batch.ClientFieldVisibility"
    provides="bika.lims.interfaces.IATWidgetVisibility"
    for="bika.lims.interfaces.IBatch"
    name="MyClientFieldVisibility" />
class ClientFieldVisibility(SenaiteATWidgetVisibility):
    """Handles the Client field visibility in Batch context
    """

    def __init__(self, context):
        super(ClientFieldVisibility, self).__init__(
            context=context, field_names=["Client"])

    def isVisible(self, field, mode="view", default="visible"):
        """Renders the Client field as hidden if the current mode is "edit"
        """
        if mode == "edit" and IClient.providedBy(self.context.aq_parent):
            return "readonly"

        return default

Current behavior before PR

Visibility settings "invisible", "readonly" and "hidden" were not supported in mode "edit".

Desired behavior after PR is merged

Visibility settings "invisible", "readonly" and "hidden" are supported in mode "edit"

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

Copy link
Contributor

@ramonski ramonski left a comment

Choose a reason for hiding this comment

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

Works as expected, thanks!

@ramonski ramonski merged commit 39745ea into master Nov 7, 2019
@ramonski ramonski deleted the referencewidget-visibility branch November 7, 2019 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants