Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Cannot display properties from SnippetChooserPanel in titleTemplate #46

Open
roodie opened this issue Aug 15, 2019 · 2 comments
Open

Cannot display properties from SnippetChooserPanel in titleTemplate #46

roodie opened this issue Aug 15, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@roodie
Copy link

roodie commented Aug 15, 2019

I have a very simply structblock:

class MemberRoleBlock(BaseBlockMixin, blocks.StructBlock):
    member= SnippetChooserBlock(target_model='members.Member', required=True)
    role = blocks.CharBlock(required=False)

    @property
    def definition(self):
        definition = super(PersonRoleBlock, self).definition
        definition['titleTemplate'] = "${member}"
        return definition

... but I have to display the name of the member as the title when the block is collasped. The problem is that the value for member at this stage is the id. Is there any hack, monkey patch, really, any solution to get the actual member.name field displayed as the title? I am completely stuck.

@BertrandBordage BertrandBordage added the enhancement New feature or request label Aug 21, 2019
@BertrandBordage
Copy link
Contributor

Unfortunately, it’s not possible without doing a case by case modification of the widgets JS: the value itself is an ID, so we would have to somehow make it available in the <input />.
We could decide to always use data-title to store that value that would be used as a title when it’s available. It’s possible, but that would require an additional MutationObserver I guess.

So doable, but requires changing a bit all the non-text JS files. Currently I’m struggling a bit to keep their changes up to date with the latest Wagtail changes.
@gasman & I are currently working on gradually merging React StreamField changes into Wagtail instead of merging everything at once. As soon as we have finished merging the new styles (wagtail/wagtail#5476), we will merge JS changes like the snippet JS changes, and finally react-streamfield itself. Once all merging is done, we can reconsider making that enhancement :)

@roodie
Copy link
Author

roodie commented Aug 21, 2019

Sure, I was able to do something similar using plain JS since my use case was rather specific (only on a specific page type and with a single specific field and stream block), but it is still a good enhancement I think.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants