Jquery
-
jQuery(document).ready(function() { jQuery.post( MyAjax.ajaxurl, { action : 'myajax-submit', information: 'weekdays' }, function( data ) { disabled_days = data; } ); jQuery.post( MyAjax.ajaxurl, { action : 'myajax-submit', information: 'baddates' }, function( data ) { disabled_days2 = data; } ); jQuery( "#date" ).datepicker("option", { beforeShowDay: disable, minDate: "0" }); function disable(date){ var day = date.getDay(); var dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear(); if(in_array(day, disabled_days) == true){ return [false, '']; }else if(in_array(dmy, disabled_days2) == true){ return [false, '']; }else{ return [true, '']; } }; function in_array (needle, haystack, argStrict) { var key = '', strict = !! argStrict; if (strict) { for (key in haystack) { if (haystack[key] === needle) { return true; } } } else { for (key in haystack) { if (haystack[key] == needle) { return true; } } } return false; } });
Uses this to get this value to disabled_days2:
["11-2-2013","12-2-2013","13-2-2013","14-2-2013","15-2-2013","16-2-2013","17-2-2013","18-2-2013","19-2-2013","20-2-2013","21-2-2013","22-2-2013","23-2-2013","24-2-2013","25-2-2013","26-2-2013","27-2-2013","28-2-2013","1-3-2013","2-3-2013","3-3-2013","4-3-2013","5-3-2013","6-3-2013","7-3-2013","8-3-2013","9-3-2013","10-3-2013","11-3-2013","12-3-2013","13-3-2013","14-3-2013","15-3-2013","16-3-2013","17-3-2013","18-3-2013","19-3-2013","20-3-2013","21-3-2013","18-3-2013","19-3-2013","20-3-2013","21-3-2013"]
. BUT the dates dosent get disabled? The disableing of the weekdays works tho. On my page i do this to call script:wp_enqueue_script( 'my-ajax-request', plugin_dir_url( __FILE__ ) . 'js/script.js', array( 'jquery-ui-datepicker' ) ); wp_localize_script( 'my-ajax-request', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
When i just used php to echo the varibles it worked fine.
- The topic ‘Jquery’ is closed to new replies.