blockOpts is undefined when adding a StreamField inside InlinePanel
See original GitHub issueIssue Summary
Trying to use Wagtailmenus (and override menu items as per documentation, but getting a JavaScript error: Uncaught TypeError: Cannot read property ‘initializer’ of undefined in stream.js (line 87)
Steps to Reproduce
- Start a new project with
wagtail start myproject
- Add the wagtailmenus extension found here.
- Extend wagtailmenus by adding overrides as per this link , but instead of a CharBlock field add a StreamField (that calls a StructBlock) (example below)
- Run migrate / makemigrations
- Visit the admin section and go to Settings > Main menu and click on ADD MENU ITEMS
- The form should appear with the added StreamField at the bottom - click the icon to create a new StreamField item
- The JavaScript error will be thrown
More information
I believe this JavaScript code var blockTypeName = $('#' + sequenceMember.prefix + '-type').val();
is looking for a hidden field which does not exist in the DOM.
My Code
class ManualSubMenuFieldBlock(StructBlock):
manual_link_url = CharBlock(required=True, max_length=255)
manual_link_text = CharBlock(required=True, max_length=255)
class Meta:
icon = 'form'
template = "home/blocks/manual_sub_menu_field_block.html"
label='Manual Sub Items'
# new wagtail custom menu system
class CustomMainMenuItem(AbstractMainMenuItem):
"""A custom menu item model to be used by ``wagtailmenus.MainMenu``"""
menu = ParentalKey(
'wagtailmenus.MainMenu',
on_delete=models.CASCADE,
related_name="custom_menu_items", #Add a setting to base.py to use your custom model
)
manual_subs = StreamField([
('manual_sub_menu', ManualSubMenuFieldBlock()),
], null=True, blank=True)
# Also override the panels attribute, so that the new fields appear
# in the admin interface
panels = AbstractMainMenuItem.panels + [
StreamFieldPanel('manual_subs'),
]
this setting must be in the base.py (settings) file…
WAGTAILMENUS_MAIN_MENU_ITEMS_RELATED_NAME = "custom_menu_items"
Technical details
- Python version: 3.6.8
- Django version: 2.1.8
- Wagtail version: 2.4.
- Browser version: Chrome 73
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Using Stream Field in WagTail throws an error in block content
Error message is: 'richtext' template filter received an invalid value; expected string, got <class 'wagtail.core.blocks.stream_block.
Read more >StreamField within an Inline Panel causing object is not ...
I'm running into an error when I try to add a related model that has a StreamField defined. When ever I try to...
Read more >How to Add a Basic StreamField to your Wagtail CMS Page
In this lesson we are going to learn how to add a basic StreamField to a a generic Wagtail CMS Page. We'll create...
Read more >How to Use ListBlocks in Wagtail CMS to Create Repeating ...
Occasionally you'll want a StreamField that can have multiple repeating content areas. A good example is the design component known as a ...
Read more >Panel types — Wagtail Documentation 4.1.1 documentation
Deprecated; use FieldPanel instead. Changed in version 3.0: StreamFieldPanel is no longer required for StreamField .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @robnardo,
Your
SubmenuItemsModel
needs apanels
definition, to ensure that the streamfield is being rendered using aStreamFieldPanel
:Hi @gasman - Please reopen this issue. I am able to reproduce this error using only Wagtail (not installing other modules). I changed title of this bug since this test involves a StreamField within an InlinePanel.
Steps to reproduce: