0

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?

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.