wagtail icon indicating copy to clipboard operation
wagtail copied to clipboard

wagtail forms placeholder

Open onno-timmerman opened this issue 4 years ago • 4 comments

Is your proposal related to a problem?

If I'm not mistaken there is no way to add placeholders. When you create a forms via wagtail there is no way to add a placeholder.

Describe the solution you'd like

add besides help_text also placeholder to the form builder

No you have to override get_from method from AbstractForm class to do it. If you are beginner you don't know how to do this.

    def get_form(self, *args, **kwargs):
        form = super().get_form(*args, **kwargs)
        for field in form.fields:
            form.fields[field].widget.attrs['placeholder'] = form.fields[field].label
        return form

onno-timmerman avatar Jun 09 '20 13:06 onno-timmerman

Still think the formbuilder should have a placeholder field?

onno-timmerman avatar Oct 10 '22 11:10 onno-timmerman

Added needs design decision. See https://github.com/wagtail/wagtail/issues/2328 for context but placeholder usage is considered a bit of an anti-pattern so we may not want to explicitly support this.

However, we should check how easy it is to use the documented approaches of overriding field attrs if someone wants to do this.

lb- avatar Oct 11 '22 22:10 lb-

Personally I’d be ok with us adding support for placeholders in the form builder, as long as the help text for the field provides guidance on appropriate usage.

thibaudcolas avatar Oct 13 '22 09:10 thibaudcolas

ok - will remove label - leave this open for someone to pick up if they want to implement a PR for this.

lb- avatar Oct 15 '22 00:10 lb-