relu / contact-form-7-datepicker

Datepicker for Contact Form 7 Wordpress Plugin based on JQueryUI's datepicker (NO LONGER MAINTAINED)
http://wordpress.org/plugins/contact-form-7-datepicker/
28 stars 34 forks source link

watermark class removal might interfer with custom function #39

Closed danielocdh closed 11 years ago

danielocdh commented 11 years ago

On the last commit you added this: function generate_code, datepicker.php

        // Remove watermark class onSelect
        $out .= ".datepicker('option', 'onSelect', function(){ $(this).removeClass('watermark'); });\n";

I had a working external js that used the ".mydate" on other places, it is not working now. Something like this:

$('input.mydate').change(function () {
  alert($(this).datepicker('getDate'));
});
relu commented 11 years ago

Use this:

jQuery(function($){
  $('.mydate').datepicker('option', 'onSelect', function(){
    var $this = $(this);
    alert($this.datepicker('getDate'));

    $this.removeClass('watermark'); // you can leave this out if you're not using watermarks
  });
});

Let me know if this works for you.

danielocdh commented 11 years ago

Thank you this will work for me now but, it probably only works if my code is after the plugin code not before, isn't this a jquery ui bug anyway?

relu commented 11 years ago

No, it's not a jQuery UI bug, it seems the default onSelect triggers the change event and since I've already overridden it it will not fire.

Maybe I'll add a $(this).trigger('change'); to keep things under control and support expected behavior.

About the order, that's normal... your code basically needs to be evaluated after so it overrides the plugin's override of onSelect :)