Issue
I just want to know how can I set initial values to empty_form.
I do create the Inlines with initial values for extra forms without problem, but, when user clicks to Add button, the fields I expect it have the initial values show up empty, and I hope it have the same initial values than extra forms.
How could I make the empty_form
to be filled with initial data?
Thanks in advance.
Solution
Django doesn't really provide a way to set initial values for empty forms. I've found a couple ways to work around this:
- Set the field values dynamically in javascript.
- Overwrite the empty_form property for your formset.
example:
formset = formset_factory(MyClass, **kwargs)
empty = formset.empty_form
# empty is a form instance, so you can do whatever you want to it
my_empty_form_init(empty_form)
formset.empty_form = empty_form
Answered By - Jkk.jonah
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.