Impossible to use after $datepickersContainer is removed from the DOM
mholt opened this issue · 5 comments
I have an SPA where the <body>
is replaced on page transitions, and a new date picker needs to be created. Unfortunately this makes it impossible to use AirDatepicker after a page with an AirDatepicker is replaced with a new page that also has an AirDatepicker, because the lib only allows creating a container element once:
air-datepicker/src/datepicker.js
Lines 37 to 44 in 76235dc
This results in an error when clicking the input to open the date picker, because this.$datepicker.offsetParent
from this line:
air-datepicker/src/datepicker.js
Line 710 in 76235dc
is null, so it goes boom 💥 on this line:
air-datepicker/src/datepicker.js
Line 742 in 76235dc
I think a more robust approach would be to allow creating the container again if it does not still exist in the DOM.
Edit: I should clarify, this is only an issue when container
is not specified in the options when constructing a new AirDatepicker. The problem is that I can't pass in a container because at the time of constructing it I do not know where it will go yet.
Added extra check if container still exists on init, should do the trick
@t1m0n Oh awesome!! I will try it as soon as I can, thank you!
PS. Air Datepicker has been amazing to work with otherwise. It has just about everything I was looking for and will be very suitable for my rather advanced use case :) (I'm building a timeline project, so lots of dates and times.) Thank you for building/maintaining it!
Finally had a chance to test this. It seems to work for me! Thank you very very much! 💯