wagtail-deprecated / wagtail-react-streamfield

Powerful field for inserting multiple blocks with nesting. (NO LONGER MAINTAINED - See Wagtail 2.13 Release Notes)
https://wagtail.github.io/react-streamfield/public/
BSD 3-Clause "New" or "Revised" License
74 stars 23 forks source link

Option to show elements collapsed by default #65

Open jkevingutierrez opened 4 years ago

jkevingutierrez commented 4 years ago

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

zerolab commented 4 years ago

Have you tried https://github.com/wagtail/wagtail-react-streamfield#meta-attributes-or-passed-to-__init__ ?

jkevingutierrez commented 4 years ago

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

gasman commented 4 years ago

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

jkevingutierrez commented 4 years ago

@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