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

AjaxSelectWidget: Saved Value from SimpleVocabulary displayed wrong #519

Closed
pbauer opened this issue Jul 9, 2015 · 3 comments
Closed

AjaxSelectWidget: Saved Value from SimpleVocabulary displayed wrong #519

pbauer opened this issue Jul 9, 2015 · 3 comments

Comments

@pbauer
Copy link
Member

pbauer commented Jul 9, 2015

AjaxSelectWidget displays the value instead of the tile of a item from a SimpleVocabulary.

To reproduce create a dx-content type wit a field using the AjaxSelectFieldWidget and a SimpleVocabulary.

DummyVocabulary = SimpleVocabulary(
    [SimpleTerm(value=u'gold', title=_(u'Gold Sponsor')),
     SimpleTerm(value=u'silver', title=_(u'Silver Sponsor'))])

Use it in a schema:

dummyfield = schema.List(
    title=_(u'Dummy'),
    value_type=schema.Choice(
        title=_(u'Dummy'),
        vocabulary=DummyVocabulary),
    required=False,
)
form.widget(
    'dummyfield',
    AjaxSelectFieldWidget,
    vocabulary=DummyVocabulary,
)

When I edit the field I see the correct options (e.g. "Gold Sponsor"). That is also used when I select a value. But after saving a value and when re-editing the object the saved value displayed in the field will now be "gold" instead of "Gold Sponsor".

The problem does not appear when using a NamedVocabulary:

@implementer(IVocabularyFactory)
class DummyVocabulary(object):

    def __call__(self, context):
        return SimpleVocabulary([
            SimpleTerm(value=u'gold', title=_(u'Gold Sponsor')),
            SimpleTerm(value=u'silver', title=_(u'Silver Sponsor')),
        ])

DummyVocabularyFactory = DummyVocabulary()

registered like this:

  <utility
    component=".dummy.DummyVocabularyFactory"
    name="mypackage.DummyVocabulary"
    />

Used in the schema like this:

dummyfield = schema.List(
    title=_(u'Dummy'),
    value_type=schema.Choice(
        title=_(u'Dummy'),
        vocabulary='mypackage.DummyVocabulary'),
    required=False,
)
form.widget(
    'dummyfield',
    AjaxSelectFieldWidget,
    vocabulary='mypackage.DummyVocabulary',
)
@vangheem
Copy link
Member

I think you want to use SelectFieldWidget instead of the ajax widget. ajax widget is for dynamic vocabularies.

@pbauer
Copy link
Member Author

pbauer commented Jul 14, 2015

@vangheem you are right. SelectFieldWidget works perfectly with a static vocabulary.

@pbauer pbauer closed this as completed Jul 14, 2015
@thet
Copy link
Member

thet commented Jul 14, 2015

sounds a bit as if it would be related to plone/plone.app.content#34 " Fix encoding problems with Mockup Select2 widget" where I was probably doing a mistake. don't know yet, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants