I have discovered (minor) issue with jQuery Datepicker plugin:
Here is a sample code:
<div class="someWidget"> <input id="myId" class="datepicker"/> </div> .... <div class="someOtherWidget"> <input id="myId" class="datepicker"/> </div>
This will add datepickers on both input fields, and when they gain focus, widget will be displayed (that’s default behaviour). So far so good. But if you click on any date, it will be passed set in the first field and the first field only. Even if datepicker is displayed below the second field, the value will never be passed to it.
Why does this happen? Because of id. Datepicker uses it internally to know to which input field the date should be passed to. If you don’t supply the id in html, then datepicker will come up with its own unique id. But it will never overwrite id, if it is already set.
Hope this will help someone, it took me some time to find out what was happening.
If your datepickers share same id, and one of them is hidden, you may even get this exception: “cannot set property ‘currentDay’ of undefined”. I wanted to show it in a demo, but for some reason I was not able to reproduce it, probably there was something more involved than just ids.
Saved me! Thanks bro!
Many thanks. Didn’t think of ids and Rails just generated them duplicate. Now I care for them to be unique and all works as expected 🙂
Thanks a lot, my problem was that I had a form tag and an input tag with the same ID
I know it’s been a while since this post, but I wanted to thank you for posting it. I was tearing my hair out on this one until I discovered that my Add and Edit forms being created in jQueryUI Dialogs had the same ID for the date field.
Thanks for the tip!
Thanks bro, this really did helped me..
Note that this error came up as:
TypeError: ‘undefined’ is not an object (evaluating ‘=f.currentDay=d(“a”,e).html()’)
…for me in Safari. Thanks for the tip!
thanks a lot for the tip!
Thanks! That really saved me a lot of time!! Just curious on how you went on to debug this problem?
Well… I don’t really remember 🙂 I use Console in Google Chrome or Firebug in Firefox…so it must have been in one of those.
If you use Visual Studio then it is now by far the best debugging tool for MS IE. (Without it debugging MS IE sucks…)
Thanks, I fixed my error
Thank you very much. You solved my problem. It is very strange.
I have add & edit forms with same IDs for the fields. And at one point of time, only one of the forms is added to the page. The other doesn’t get added to the DOM at all. But, I see the error. After I made the IDs different, the error is gone now.
Thanks a lot, it helps me lot, coz id’s only works on first instance on page.
Comments are closed.