Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datepicker applies to wrong field

I'm facing a little problem with my jQuery UI datepicker. The thing is, I have my page and some input like this :

blabla | blabla | .date-picker | blabla
blabla2 | blabla2 | .date-picker | blabla2
blabla3 | blabla3 | .date-picker | blabla3

So the 'blabla' are just some text, and the '.date-picker' is an input, with the 'date-picker' class.

In my JavaScript code I have just the following :

$(function() {
    $('.date-picker').datepicker();
});

But for example, if I click on the input of the line "blabla3", instead of updating the right input, it always updates the first one...

My input have all the same id (I can't change it), but I'm using the class of the input for my selector, so it should work but doesn't.

like image 876
user1506157 Avatar asked Sep 07 '12 07:09

user1506157


2 Answers

Hello old post but it's for those who are still facing this problem...

Just remove the id of the new input, datepicker always generates a new id i.e. if the input doesn't have one. If it had one the datepicker would keep that, which mean here the first input was cloned and the last will also be updated.

like image 194
douxsey Avatar answered Nov 12 '22 12:11

douxsey


You should change the id of your inputs, else it will not work, because, when you select any date, it use DP_jQuery_1347006322116.datepicker._selectDay('#same',8,2012, this);return false; this function to selectDay, and it is taking the id for the input.

so if you have multiple id, it will select first input and set the day there.

like image 3
Yograj Gupta Avatar answered Nov 12 '22 10:11

Yograj Gupta