c# - Disable dates from dropdownlist in datepicker -


i have dropdownlist dates. , can iterate through dates in jquery. have datepicker , want disable dates dropdownlist in datepicker.

the id of dropdownlist is: #form_one3.

and javascript this:

inp.datepicker({     dateformat: dateformat,     changemonth: true,     beforeshowday: function(date) {         $("#form_one3 > option").each(function() {             //alert(this.text);               var array = [this.text].tostring();             alert(array.tostring());             var string = jquery.datepicker.formatdate('yy-mm-dd', date);             return [array.indexof(string) == -1];         });     },     changeyear: false,     showweek: true,     firstday: 1,     yearrange: "c-100:c+15",     showon: inp.hasclass("ui-date-picker-onfocus") ? "focus" : "button" }) 

if this:

$("#form_one3 > option").each(function() {     alert(this.text); }); 

i see dates dropdownlist.

but complete javascript file gives empty values , datepicker doenst work anymore.

thank you

if $("#form_one3 > option:gt(1)").each(function () { between beforeshowday: function (date) {

the datepicker doesnt work anymore.

so put .each funtion then, datepicker work.

thank

the format this:

<option value="2015-07-27t00:00:00z">27-7-2015</option> 

i have this:

 inp.datepicker({                             dateformat: dateformat,                             beforeshowday: function (date) {                                                                 $("#form_one3 > option:gt(1)").each(function () {                                                                     var array = [this.text].tostring("yy-mm-dd");                                     var string = jquery.datepicker.formatdate('yy-mm-dd', date);                                     return [array.indexof(string) == -1];                                 });                              },                               changemonth: true,                             changeyear: false,                             showweek: true,                             firstday: 1,                             yearrange: "c-100:c+15",                             showon: inp.hasclass("ui-date-picker-onfocus") ? "focus" : "button"                         }) 

but error:

error: unable property '0' of undefined or null reference

and if debug see every time that:

return [array.indexof(string) == -1];

string : 29-06-2015.

this complete script:

; (function ($) {     $(function () {         $("form.xforms-form").bind({             xforms_enrich: function (e) {                 if ($.fn.datepicker) {                     $("input.qmatic-dateslot", e.args.data).each(function () {                         var inp = $(this);                         if (inp.is(":disabled")) return;                         var tabindex = inp.attr("tabindex");                          var dateformat = $.xforms.getproperty(inp, 'dateformat') || 'd-m-yy';                         dateformat = dateformat.replace(/m/g, '0').replace(/h/gi, '0').replace(/t/g, '').replace(/m/g, 'm').replace('yyyy', 'yy');                          $("#" + inp.attr("id") + " ~ button.ui-datepicker-trigger").attr("tabindex", tabindex);                          var clearbtn = $('<button class="ui-datepicker-clear" type="button" tabindex="' + tabindex + '">x</button>').click(function () { inp.val(''); inp.change(); return false; });                         inp.after(clearbtn);                          inp.datepicker({                             dateformat: dateformat,                             beforeshowday: function (date) {                                                                 $("#form_one3 > option:gt(0)").each(function () {                                     //alert(this.text + ' ' + this.value);                                     //var array = ["2015-03-14", "2015-03-15", "2015-03-16"];this works :)                                     var array = [this.text].tostring("yy-mm-dd");                                     var string = jquery.datepicker.formatdate('yy-mm-dd', date);                                     return [array.indexof(string) == -1];                                 });                              },                               changemonth: true,                             changeyear: true,                             showweek: true,                             firstday: 1,                             yearrange: "c-100:c+15",                             showon: inp.hasclass("ui-date-picker-onfocus") ? "focus" : "button"                         })                     });                     $("#ui-datepicker-div").hide();                 }             }         })     }) })(jquery); 

it breaks on line:

unselectable = (othermonth && !selectothermonths) || !daysettings[0] ||                             (mindate && printdate < mindate) || (maxdate && printdate > maxdate); 

and error:

unable property 0 of undefined or null reference 

i tried this:

 inp.datepicker({                             dateformat: dateformat,                             beforeshowday: function (date) {                                                                 $("#form_one3 > option:gt(0)").each(function (key, value) {                                      if (date == value.tostring('d-m-yy')) {                                         var array = [this.text].tostring("d-m-yy");                                         var string = jquery.datepicker.formatdate('d-m-yy', date);                                         return [array.indexof(string) == -1];                                     }                                     else {                                         return 0;                                     }                                 });                              },                               changemonth: true,                             changeyear: true,                             showweek: true,                             firstday: 1,                             yearrange: "c-100:c+15",                             showon: inp.hasclass("ui-date-picker-onfocus") ? "focus" : "button"                         }) 

i assume basing code on this related question. think want is, in beforeshowday, check if date of dates in drop down. depending on version of jquery, can use either find() or filter(). think need format date in same format option text, no leading zeroes in month or date , day month year.

try if using jquery > 1.9:

beforeshowday: function (date) {                                    var datestring = jquery.datepicker.formatdate('d-m-yy', date);     return ($('#form_one3 option').filter(function () { return $(this).html() == datestring; }).length == 0); } 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -