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

unicorn does not work with form helpers e.g. crispy #362

Open
krystofbe opened this issue Feb 16, 2022 · 2 comments
Open

unicorn does not work with form helpers e.g. crispy #362

krystofbe opened this issue Feb 16, 2022 · 2 comments

Comments

@krystofbe
Copy link

just found out about this awesome library. thanks a lot. love it! <3

while playing around with the unicorn, I noticed that i can't use the form validation with form_class when using form helpers or crispy forms and get some error like this

django.template.base.VariableDoesNotExist: Failed lookup for key [form]  ...

this is probably related to #324.

has anybody found a way to make the unicorn validation functionality work together with crispy forms or form helpers in general?

@adamghill
Copy link
Owner

Thanks for the nice words! I think @nerdoc mentioned some investigation with crispy forms and Unicorn in #227 which might be helpful? However, if you could make a PR with some sample code using crispy forms I could see if I could add anything to unicorn to help in future releases.

@nerdoc
Copy link
Contributor

nerdoc commented Feb 28, 2022

Bad Hack(TM): patch Unicorn, to let UnicornView inherit from FormView instead of TemplateView.

class MyForm(Form)
    email = forms.EmailField()

# Unicorn Component
class EmailView(UnicornView):
    form = MyForm

And in the template:

{% load unicorn crispy_forms_tags %}
<div>
{% crispy form %}
</div>

I just wrote this here in a few minutes, so it's not tested and copy'n'pasted, but it should work,

Whether it is a good idea to "patch" Unicorn and urge it to be a FormView - I don't know - that has to decide @adamghill - there is another discussion for that...

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants