Replies: 1 comment
-
Thanks for the example code! I'll take a look and see if there is a bug lurking around. :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am struggling with forms and Unicorn. In your examples, you have (undocumented) usage of a form that uses the
unicorn:submit.prevent
attribute. With "undocumented" I don't meansubmit
, which is an Js event, norprevent
, which has good docs: I mean that it's not quite clear (for me) how to deal with forms and Unicorn in general.You can use
<form unicorn:submit.prevent>
and then just take a<button unicorn:click="action">
AFAIK to get the whole form to the backend. In another example you use<button type="submit" unicorn:click="hello">Hello!</button>
without any form.Both is possible, and I know I am no HTML/Js guru. But is there a way how you recommend creating forms in Django/Unicorn?
First I tried the traditional style with ModelForm, couldn't figure out how to do it properly to get a simple form with 2 inputs and a select right - one input was a MoneyField, and Django input localization is quite "buggy" here when using ModelForm....
Precisely:
In my case i have a form element with
u:prevent.submit="add_amount"
, 1 input withu:model.lazy="amount"
, 1 input withu:model.debounce-500="comment"
, a select withu:model=current_vat
, and a button withtype="submit"
. This is a child component of another, which lists all the amounts with comments and vats.When I load the page, and enter an amount + press Enter or click on the "save" button, it works, the u:models get updated, and the parent reloads itself, which I see on the screen. the components are here, the templates here.
But then, the whole component seems to become "dull", and the parent element does not reload any more after sending another values.
I tried around for days with different tags and attributes, removed the form, switched to Django's ModelForm, everything, but it just didn't work smoothly. So I came here to ask, if there was a preferred way of dealing with forms.
Or maybe I have a simple but nasty bug in that forms.
If you find a few minutes to tell me, I'd be happy. If you appreciate it, I can write some docs for forms with a PR then too.
Beta Was this translation helpful? Give feedback.
All reactions