jquery-ui datepicker not appearing on dynamic input

MikeHoss

I inherited a bunch of code of varying quality and I'm fixing a bunch of things that has been wrong. One thing that it does is that is has a table of form inputs, one of which uses jquery-ui Datepicker. There is also a button that creates a new row at the bottom of the table. The new row's Datepicker never shows up.

I've seen this problem listed a few times here on SO but none of those solutions worked. I'm putting up what I have now. My jfiddle is at:

http://jsfiddle.net/squarepegsys/G8WEC/2/

The meat of my code is here:

tr.find(".datepicker").on("focusin",function() {
    console.log("got focus");
    $(this).datepicker();

}); 

In the on("focusin"...) line, I see "got focus" on the console but never see the datepicker show up.

j08691

When you create the datepicker instance, jQuery assigns it an ID, and when you clone it, you're duplicating it. Instead, create the datepicker instance dynamically via:

$(document).on('focus', ".datepicker", function () {
    $(this).datepicker( "destroy" ).datepicker();
})

jsFiddle example

This will work for dynamically created elements and jQuery will manage the IDs properly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery UI DatePicker not appearing inside Bootbox modal loaded through Ajax

From Dev

jquery ui datepicker not working with dynamic html

From Dev

Dynamic minDate and maxDate for jQuery ui datepicker

From Dev

Dynamic minDate and maxDate for jQuery ui datepicker

From Dev

Show full date in input for jQuery UI Datepicker

From Dev

jQuery UI Datepicker works on <input> but not on <h:inputText>

From Dev

jQuery UI Datepicker works on <input> but not on <h:inputText>

From Dev

jQuery UI datepicker - input invalid on load if using $('').datepicker('option', {})

From Dev

Extending jQuery UI components ( Overriding jQuery Datepicker to prevent wrong input)

From Dev

Extending jQuery UI components ( Overriding jQuery Datepicker to prevent wrong input)

From Dev

Dynamic bootstrap ui datepicker

From Dev

Jquery UI datepicker setDate not working on dynamic change of formatDate

From Dev

How do I get a jQuery UI Datepicker button inline with the input?

From Dev

How to custom jquery ui datepicker trigger button inline with <input> tag

From Dev

Force jQuery UI Datepicker to display below input field

From Dev

Force jQuery UI Datepicker to display below input field

From Dev

JQuery Datepicker UI transparent

From Dev

setDate in jQuery UI DatePicker

From Dev

DatePicker jquery UI not working

From Dev

Extending jQuery UI datepicker

From Dev

JQuery Datepicker UI dateformat

From Dev

jQuery ui datepicker

From Dev

jquery calling datepicker on dynamic elements

From Dev

jquery datepicker dynamic with personal format

From Dev

Assign Datepicker on dynamic textboxes in jquery

From Dev

Jquery UI Draggable items appearing in one row

From Dev

jQuery UI dialog not appearing Squarespace adblock detect

From Dev

jquery datepicker ui - weeknds only

From Dev

Jquery Ui Datepicker change icons

Related Related

  1. 1

    jQuery UI DatePicker not appearing inside Bootbox modal loaded through Ajax

  2. 2

    jquery ui datepicker not working with dynamic html

  3. 3

    Dynamic minDate and maxDate for jQuery ui datepicker

  4. 4

    Dynamic minDate and maxDate for jQuery ui datepicker

  5. 5

    Show full date in input for jQuery UI Datepicker

  6. 6

    jQuery UI Datepicker works on <input> but not on <h:inputText>

  7. 7

    jQuery UI Datepicker works on <input> but not on <h:inputText>

  8. 8

    jQuery UI datepicker - input invalid on load if using $('').datepicker('option', {})

  9. 9

    Extending jQuery UI components ( Overriding jQuery Datepicker to prevent wrong input)

  10. 10

    Extending jQuery UI components ( Overriding jQuery Datepicker to prevent wrong input)

  11. 11

    Dynamic bootstrap ui datepicker

  12. 12

    Jquery UI datepicker setDate not working on dynamic change of formatDate

  13. 13

    How do I get a jQuery UI Datepicker button inline with the input?

  14. 14

    How to custom jquery ui datepicker trigger button inline with <input> tag

  15. 15

    Force jQuery UI Datepicker to display below input field

  16. 16

    Force jQuery UI Datepicker to display below input field

  17. 17

    JQuery Datepicker UI transparent

  18. 18

    setDate in jQuery UI DatePicker

  19. 19

    DatePicker jquery UI not working

  20. 20

    Extending jQuery UI datepicker

  21. 21

    JQuery Datepicker UI dateformat

  22. 22

    jQuery ui datepicker

  23. 23

    jquery calling datepicker on dynamic elements

  24. 24

    jquery datepicker dynamic with personal format

  25. 25

    Assign Datepicker on dynamic textboxes in jquery

  26. 26

    Jquery UI Draggable items appearing in one row

  27. 27

    jQuery UI dialog not appearing Squarespace adblock detect

  28. 28

    jquery datepicker ui - weeknds only

  29. 29

    Jquery Ui Datepicker change icons

HotTag

Archive