coderedcms
coderedcms copied to clipboard
wagtailstreamforms support
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 https://github.com/coderedcorp/coderedcms/issues/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..
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
@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.
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.
Well, I think there should be a choice which module to use, and this works for me without migrations:
https://github.com/coderedcorp/coderedcms/pull/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.
~~@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}}"
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
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.
@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
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!
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
(and don't run makemigrations without an app)