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

wagtail-react-streamfield.js:33 Error: Could not find input with name "field-23efd488-c187-43a5-bd3c-86f635a1e6a4"

contactr2m opened this issue · comments

commented

Wagtail V2.4
wagtail-react-streamfield V1.2.0.

Settings

    'rest_framework',
    'wagtail.contrib.forms',
    'wagtail.contrib.redirects',
    'wagtail.embeds',
    'wagtail.sites',
    'wagtail.users',
    'wagtail_react_streamfield',
    'wagtail.snippets',
    'wagtail.documents',
    'wagtail.images',
    'wagtail.search',
    'wagtail.admin',
    'wagtail.core',

    'modelcluster',
    'taggit',

SectionBreak Struct Block

class StaticHTMLInput(Widget):
    """
    Need an <input> widget that doesn't actually accept any input
    """

    input_type = "hidden"

    def __init__(self, raw_html=None, **kwargs):
        self.raw_html = raw_html
        super(StaticHTMLInput, self).__init__(**kwargs)

    def render(self, name, value, attrs=None, renderer=None):
        if self.raw_html is not None:
            return format_html(self.raw_html)
        else:
            return ""


class StaticHTMLField(Field):
    def __init__(self, raw_html=None, **kwargs):
        widget = StaticHTMLInput(raw_html=raw_html)
        super(StaticHTMLField, self).__init__(widget=widget, **kwargs)


class StaticHTMLBlock(blocks.FieldBlock):
    def __init__(self, raw_html=None, required=False, help_text=None, **kwargs):
        self.raw_html = raw_html
        self.field = StaticHTMLField(
            raw_html=self.raw_html, required=required, help_text=help_text
        )
        super(StaticHTMLBlock, self).__init__(**kwargs)

    def render(self, value, context=None):
        """
        Return a text rendering of 'value', suitable for display on templates.
        Note that we override this function so that we can render the raw HTML as this block
        is just a container; 'value' in this case will always be None
        """
        if self.raw_html is not None:
            return format_html(self.raw_html)
        else:
            return ""


class SectionBreakBlock(blocks.StructBlock):
    section_break = StaticHTMLBlock(raw_html="<hr>")

    def render(self, value, context=None):
        """
        Return a text rendering of 'value', suitable for display on templates.
        Note that we override this function so that we can render the child block as this block
        is just a container; 'value' in this case will always be None
        """
        return self.child_blocks["section_break"].render(value)

    class Meta:
        icon = "code"

I use this block in my description streamfield.
After clicking this block in CMS admin i get below errors in console and entire streamfield vanishes

wagtail-react-streamfield.js:33 Error: Could not find input with name "field-23efd488-c187-43a5-bd3c-86f635a1e6a4"
    at t.value (wagtail-react-streamfield.js:50)
    at za (wagtail-react-streamfield.js:33)
    at Va (wagtail-react-streamfield.js:33)
    at wagtail-react-streamfield.js:33
    at Object.t.unstable_runWithPriority (wagtail-react-streamfield.js:42)
    at Ou (wagtail-react-streamfield.js:33)
    at Pu (wagtail-react-streamfield.js:33)
    at Iu (wagtail-react-streamfield.js:33)
    at Ru (wagtail-react-streamfield.js:33)
    at Tn (wagtail-react-streamfield.js:33)

Am i missing anything ?

If you want something static, why not use StaticBlock? :)

commented

Thanks for the hint. its a very old code of Wagtail it seems.