Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wagtailstreamforms support #370

Open
ayushin opened this issue Oct 28, 2020 · 11 comments
Open

wagtailstreamforms support #370

ayushin opened this issue Oct 28, 2020 · 11 comments
Labels
Type: Enhancement New feature or functionality change

Comments

@ayushin
Copy link

ayushin commented Oct 28, 2020

https://github.com/labd/wagtailstreamforms/ is a handy module that manages forms as a streamfield block and has an advantage of allowing multiple forms per page and flexibility to add forms anywhere.

Because of #305 it is not possible to use wagtailstreamforms in the snippets and I think a possible solution would be integrating wagtailstreamforms into coderedcms, this is what I ended up doing in my fork.

If anybody has better ideas how I could use wagtailstreamforms without touching coderedcms - I'd be thrilled to hear it!

However I think for this particular case it would be worth taking a look at this module to include it as an alternative forms solution with coderedcms, by, i.e. setting CODEREDCMS_USE_WAGTAILSTREAMFORMS=True

So, I've discovered that you don't really need the actual migration for the streamfield to work!

I'm going to try to patch the coderedcms.blocks.CONTENT_STREAMFIELD_BLOCKS on the fly and see if I can get away with using it without performing an actual migration. To be continued..

@ayushin ayushin added the Type: Enhancement New feature or functionality change label Oct 28, 2020
@vsalvino
Copy link
Contributor

On a related note, we have integration with wagtail flexible forms... which is similar to wagtailstreamforms in many ways. Check it out and see if that might fit your needs.

https://docs.coderedcorp.com/cms/features/page_types/stream_forms.html

@ayushin
Copy link
Author

ayushin commented Oct 28, 2020

@vsalvino Yes, I've used those too, the advantage with wagtailstreamforms you can add/remove them anywhere to/from any page as you go without changing the page type. That's the main difference.

@vsalvino
Copy link
Contributor

Our recommendation is generally to centralize the form on a single page (form page). Then use the page preview block if you'd like to "embed" that form elsewhere on other pages or in other streamfields.

This way you could have, for example, a definitive sign up page with a unique URL, but also embed the form in the footer, a content wall, etc.

@ayushin
Copy link
Author

ayushin commented Oct 28, 2020

Well, I think there should be a choice which module to use, and this works for me without migrations:

#371

I might be overworked but I can't seem to figure out the way to either:

  • patch coderedcms.blocks.CONTENT_STREAMFIELD_BLOCKS on the fly (tried in init and appconfig neither works)

  • OR hide the if USE_WAGTAILFORMS from make migrations

As long as makemigrations desn't see it - there's no problem and all works as expected.

Leaving this as it is for now.

@ayushin
Copy link
Author

ayushin commented Oct 28, 2020

@vsalvino while on the subject of content walls, any quick tip how to have it hidden initially? it is displayed on load no matter what i do, i suspect some js or template doing it for me

     data-cr-wall-id="{{self.content_wall.id}}"

@vsalvino
Copy link
Contributor

The point of the content wall is to force the wall before allowing user to view the content. So currently there is no way to have a hidden wall.

If you would like a modal on your page, there is a modal block which can be toggled by the user via button.

For anything else, you might be better off to implement your own page model/template to manually control the HTML yourself: https://docs.coderedcorp.com/cms/advanced/advanced02.html

@ayushin
Copy link
Author

ayushin commented Oct 28, 2020

I've just defined a few more templates for the "contentwallblock" and all works now! Thanks!

Now if we solve the custom streamfield blocks - that would be awesome.

@ayushin
Copy link
Author

ayushin commented Oct 28, 2020

@vsalvino And talking about modals, now I'm going to use them too and I also need forms inside of the modals, another case for wagtailstreamfieldforms

@pascalthivierge
Copy link

Hi @ayushin,

I'm also interested in form blocks inside pages. Is everything working for you now? What do we need to make it work ?

Thanks in advance!

@ayushin
Copy link
Author

ayushin commented Dec 4, 2020

wagtailstreamforms_fields.py

from wagtail.core import blocks
from wagtailstreamforms.fields import BaseField


def get_form_block(self):
    """The StreamField StructBlock.

    Override this to provide additional fields in the StreamField.

    :return: The ``wagtail.core.blocks.StructBlock`` to be used in the StreamField
    """
    return blocks.StructBlock(
        [
            ("name", blocks.CharBlock()),
            ("label", blocks.CharBlock()),
            ("help_text", blocks.CharBlock(required=False)),
            ("required", blocks.BooleanBlock(required=False)),
            ("default_value", blocks.CharBlock(required=False)),
        ],
        icon=self.icon,
        label=self.label,
    )


BaseField.get_form_block = get_form_block

@ayushin
Copy link
Author

ayushin commented Dec 4, 2020

(and don't run makemigrations without an app)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or functionality change
Projects
None yet
Development

No branches or pull requests

3 participants