Initializing jQuery ui widgets dynamically

I am trying to use jQuery built-in widgets for dynamic content like ajax calls or DOM manipulations like cloning.

Now I have something that works, but is a bit hacky, and I would like to see your suggestions for improving this. It should be remembered that JS is generated by PHP, I want to avoid the situation when I need to deal with creating JS for individual pages. Be that as it may, I can simply determine the type of widget, set some variables and let PHP generate JS. The reason is that I need to pass variables from the database and provide localization on the fly to widgets.

jQuery('body').delegate('.juiDateStart', 'focusin', function (e) {
    $(this).datepicker({
        'minDate': 0,
        'onClose': function () {
            juiDtp_343875e72a11870172ae2922f7dd9f4f($(this));
        }
    });
});

The above code is great for cloning and ajax, but obviously, in order to initialize the date selection at each step, this is not an ideal solution. I also automatically download full and cascading selections using this system.

Thanks in advance.

+3
source share
1 answer

Whenever you have dynamically created Javascript functions like this, I think you can have so many abstractions before they cause additional overhead. The way that you initialize this function for each focus seems to look good.

, class-by-class ( id-by-id), (.. ...), , ( ), , .

+1

All Articles