django-bootstrap-datepicker-plus
django-bootstrap-datepicker-plus copied to clipboard
datepicker not working in a formsets
Datepickers do not show up in dynamically added empty formsets. They do show up only in formsets that are loaded with the page.
To Reproduce Create a django form with a date field: my_date = forms.DateField(widget=DatePickerInput()) Use it in a formset.
Expected behavior Statically and dynamically loaded date fields should make a JS calendar appear.
What's seen instead Only the statically loaded datepickers show the JS calendar. Nothing shows up on dynamically added formsets.
Setup Information:
- OS: [ubuntu 18]
- Browser: Chrome
- Browser version [Version 71.0.3578.80]
- Python version [3.6]
- Django version [2.1]
- Bootstrap version [4]
- jQuery version [1.7.1]
[x] I have followed the configuration instructions and checked out the common error troubleshooting page.
FYI, the issue is that there is no associated 'change' event in the generated code of added datepickers. Is there any JS piece of code that should be run in order to add the events to the new datepickers? Thank you.
I figured out a dirty solution by taking the whole function from js/datepicker-widget.js and calling it in the dynamically added formset piece of code. Is there any cleaner solution for that? Thank you
Sorry there is no cleaner solution for that. Can you specify which library you are using to generate dynamic inputs?
I'm facing the same issue. I'm not using a library to generate the dynamic inputs. I'm cloning and updating the necessary elements myself. It would be very helpful if there were a callable function, that would re-search the page and associate all pickers anew.
Would you be able to provide any more details on how you were able to get this to work? I am facing the same issue using the django-dynamic-formset package and have not found a solution yet. I am using django-bootstrap-datepicker-plus for the datepicker.
If I remember correctly I copied the content of js/datepicker-widget.js into my own file somewhere and called the function manually after cloning the element. I no longer have access to the code, so I can't help further than this.
Anybody found a solution to this problem?
So far my, "dirty" solution is this:
<input type="date" value='{{ form.my_date.as_p }}'>
I used widget_tweaks to overide type as date:
{% render_field field type="date" class+="form-control" %}
From version 5.0.0 the widgets work with django-dynamic-formset.