python-discord / django-crispy-bulma

Django application to add 'django-crispy-forms' layout objects for Bulma.io
MIT License
25 stars 9 forks source link

Disentangle and document input fields with icons #10

Open lemonsaurus opened 5 years ago

lemonsaurus commented 5 years ago

It looks like there's already a feature in this fork for an input field with icons prepended or appended.

This is a useful feature, so we need to figure out how it works and then document it in our readme.

I think it's probably supposed to be a CrispyForms Layout object, so inside the __init__ of the forms.Form object you'd add a Layout(InputFieldWithIcons(...)) or something like that, but I haven't gotten it working yet.

gdude2002 commented 5 years ago

It works pretty much how you'd expect.

class SetupForm(Form):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.helper = FormHelper(self)

        self.helper.layout = Layout(
            IconField("username", icon_prepend="user", title="Username"),
            IconField("email", icon_prepend="at", title="Email"),
            IconField("password", icon_prepend="key", title="Password"),
            IconField("confirm_password", icon_prepend="key", title="Password (Again)"),
            Submit("submit", "Submit", css_class="is-fullwidth")
        )

The only problem is that this field doesn't render error text like the regular input does:

image

Here's what the normal input does if you have errors:

image

I've been looking into how to fix this, but I haven't figured it out yet.

gdude2002 commented 5 years ago

Oh, and it also doesn't support placeholders, but that's a quick fix. I'm not entirely sure if anything does, though.