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

Option to show elements collapsed by default

jkevingutierrez opened this issue · comments

I was wondering if there is an option to collapsed elements by default?

If not, It could be an extra boolean option closed added to the StreamField/StreamBlock, if set to True, it will show the elements collapsed by default

Hi @zerolab thanks for answering,

Sorry I wasn't clear enough. Yes, I have tried that one, but you need to add that option to the Meta of each Block.

I was wondering if there was an option that could be added to the StreamField itself. Something like:

body = StreamField([
        Block1,
        Block2,
        ....
    ],
        closed=True,
        null=True,
        blank=True)

There could be cases where you want a Block to be collapsed by default for some specific StreamFields, but show it in others

@jkevingutierrez Try:

body = StreamField(
    blocks.StreamBlock([
       ...
    ], closed=True),
    null=True, blank=True)

(a StreamBlock at the top level like this is equivalent to passing the list of child blocks directly to StreamField, and passing parameters to the Block definition is equivalent to setting them in Meta)

@gasman just tried that one, but it didn't work for me.

My code looks like this:

from wagtail.admin.edit_handlers import StreamFieldPanel
from wagtail.core import blocks
from wagtail.core.fields import StreamField
from wagtail.core.models import Page

class CustomHomePage(Page):
    body = StreamField(blocks.StreamBlock([
        ...
    ], closed=True),
    null=True,
    blank=True)

    content_panels = Page.content_panels + [
        StreamFieldPanel('body'),
    ]

Django: 3.0.9
Wagtail:2.9.3
wagtail-react-stream-field: 1.3.6