Baral
Baral

Reputation: 3141

jquery-ui datepicker issue

I have an application where I have multiple date fields. All of these fields are datepicker.

This application also have some processes where it updates automaticly the value of these fields using

$('#selector').datepicker('setDate', aDate);

The problem is when the focus is on another field and the calendar is opened, it's sets the date to the last 'selector' called by the setDate method...

Here is a jsFiddle that reproduces the problem I am facing.

To reproduce the problem.

  1. Run the jsFiddle
  2. Click on the first input field (the calendar opens)
  3. Wait until the 3rd input field is populated with the current date (about 5secs)
  4. Select a date.
  5. --->Problem, the selected date updated into the 3rd field...

jsFiddle

Any way to avoid this?

Upvotes: 0

Views: 49

Answers (1)

Slippery Pete
Slippery Pete

Reputation: 3110

Maybe try to detect if one of your inputs already has focus, then refresh it after the auto-populate of dt3. Seems kind of hackish though.

$("input").datepicker();

setTimeout(function () {
    var focused = $('input:focus');
    $('#dt3').datepicker('setDate', new Date());
    if (focused) {
        focused.datepicker('refresh');
    }    
}, 5000);

http://jsfiddle.net/Nza9u/3/

Upvotes: 1

Related Questions