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

StaticCatalogVocabulary with AjaxSelectFieldWidget shows only UID on edit page #94

Open
ewohnlich opened this issue Jul 22, 2024 · 0 comments

Comments

@ewohnlich
Copy link

This error also involves plone.app.relationfield, please advise if I should file an issue there as well or in lieu of this one.

When using StaticCatalogVocabulary with a RelationList/Choice and the StaticCatalogVocabulary, "add" forms work as expected but "edit" forms do not, when there is an existing value assigned to the context's field.

image

As a proof of concept I edited plone.app.relationfield.behavior to use the example from the docs https://6.docs.plone.org/backend/relations.html?highlight=staticcatalogvocabulary#using-different-widgets-for-relations almost verbatim.

from plone.app.z3cform.widget import RelatedItemsFieldWidget
from plone.autoform import directives as form
from plone.app.z3cform.widgets.select import AjaxSelectFieldWidget
from plone.autoform.interfaces import IFormFieldProvider
from plone.base import PloneMessageFactory as _
from plone.supermodel import model
from plone.supermodel.directives import fieldset
from z3c.relationfield.schema import RelationChoice
from z3c.relationfield.schema import RelationList
from zope.interface import provider
from plone.app.vocabularies.catalog import StaticCatalogVocabulary


@provider(IFormFieldProvider)
class IRelatedItems(model.Schema):
    """Behavior interface to make a Dexterity type support related items."""

    relatedItems = RelationList(
        title=_("label_related_items", default="Related Items"),
        default=[],
        value_type=RelationChoice(
            title="Related",
            vocabulary=StaticCatalogVocabulary(
                {
                    "review_state": "published",
                },
                title_template="{brain.Type}: {brain.Title} at {path}",  # Custom item rendering!
            )
            #vocabulary="plone.app.vocabularies.Catalog"
        ),
        required=False,
    )
    form.widget(
        "relatedItems",
        AjaxSelectFieldWidget,
        pattern_options={  # Some options for Select2
            "ajax": {"quietMillis": 500},  # Wait 500ms after typing to make query
        },

    )
    # form.widget(
    #     "relatedItems",
    #     RelatedItemsFieldWidget,
    #     vocabulary="plone.app.vocabularies.Catalog",
    #     pattern_options={
    #         "recentlyUsed": True  # Just turn on. Config in plone.app.widgets.
    #     },
    # )

    fieldset("categorization", label=_("Categorization"), fields=["relatedItems"])

To reproduce:

  1. Create a Page (page1) and publish
  2. Create another Page (page2) and in the related items field select page1. Save.
  3. Edit page2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant