django-bootstrap-datepicker-plus icon indicating copy to clipboard operation
django-bootstrap-datepicker-plus copied to clipboard

datepicker not working in a formsets

Open KrzysztofW opened this issue 6 years ago • 8 comments

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.

KrzysztofW avatar Apr 09 '19 09:04 KrzysztofW

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.

KrzysztofW avatar Apr 09 '19 09:04 KrzysztofW

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

KrzysztofW avatar Apr 09 '19 12:04 KrzysztofW

Sorry there is no cleaner solution for that. Can you specify which library you are using to generate dynamic inputs?

monim67 avatar Apr 15 '19 15:04 monim67

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.

Bloodmallet avatar May 29 '19 07:05 Bloodmallet

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.

widg3tt avatar Nov 05 '19 19:11 widg3tt

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.

Bloodmallet avatar Nov 05 '19 19:11 Bloodmallet

Anybody found a solution to this problem? So far my, "dirty" solution is this: <input type="date" value='{{ form.my_date.as_p }}'>

JDBasic avatar Nov 18 '20 18:11 JDBasic

I used widget_tweaks to overide type as date:

{% render_field field type="date" class+="form-control" %}

anoopksharma22 avatar Apr 18 '22 20:04 anoopksharma22

From version 5.0.0 the widgets work with django-dynamic-formset.

monim67 avatar Nov 12 '22 18:11 monim67