wagtail-deprecated / wagtail-react-streamfield

Powerful field for inserting multiple blocks with nesting. (NO LONGER MAINTAINED - See Wagtail 2.13 Release Notes)

Home Page:https://wagtail.github.io/react-streamfield/public/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot display properties from SnippetChooserPanel in titleTemplate

roodie opened this issue · comments

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.

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 :)

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.