jQuery UI datepicker and Dynamic Forms

Posted: March 16, 2010 in JavaScript

When implementing jQuery UI’s datepicker in a dynamic form, you may notice that it will break as you bind it to new elements. The datepicker method adds a “hasDatepicker” class which must be removed first.

This example finds all the elements with a “datePicker” class and removes the “hasDatepicker” class from the element. It then calls the datepicker method and binds the .datePicker class again.

$('body').find(".datePicker").removeClass('hasDatepicker').datepicker();

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s