javascript - How to make a range of dates avaible in DatePicker mvc4 -


i have method generate range of dates. want make range of dates avaible in datepicker , rest of dates has disabled.

this jquery:

;(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,                             changemonth: true,                              beforeshowday: function(date) {                                  var array = $.getjson("/qmatic/getavailabledates"); //["2015-03-14", "2015-03-15", "2015-03-16"];                                 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"                          })                      });                      $("#ui-datepicker-div").hide();                 }             }         })     }) })(jquery); 

and method generates availeble in class: qmatic:

public availabledates getavailabledates(string branchpublicid, string servicepublicid)         {             httpwebrequest httprequest = createhttprequest("calendar-backend/public/api/v1/branches/" + branchpublicid + "/services/" + servicepublicid + "/dates", httpmethod.get, "application/json");             string json = get(httprequest);             return jsonconvert.deserializeobject<availabledates>(json);         } 

so has client side. because dates available. how enable range in datepicker , disable other dates?

thank you

i try this:

 inp.datepicker({                             dateformat: dateformat,                             changemonth: true,                             url: "/qmatic/getavailabledates",                             type: "get",                              beforeshowday: function (date) {                                   var array = url; //$.getjson("/qmatic/getavailabledates");  //["2015-03-14", "2015-03-15", "2015-03-16"];                                 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"                          }) 

but datepicker doenst work anymore

so hardcoded:

 var array = ["2015-03-14", "2015-03-15", "2015-03-16"]; 

but how extract dates method:

public availabledates getavailabledates(string branchpublicid, string servicepublicid)         {             httpwebrequest httprequest = createhttprequest("calendar-backend/public/api/v1/branches/" + branchpublicid + "/services/" + servicepublicid + "/dates", httpmethod.get, "application/json");             string json = get(httprequest);             return jsonconvert.deserializeobject<availabledates>(json);         } 

thank you!

this output of json:

{"notifications":[],"dates":["2015-07-22t00:00:00","2015-07-23t00:00:00","2015-07-24t00:00:00","2015-07-27t00:00:00","2015-07-28t00:00:00","2015-07-29t00:00:00","2015-07-30t00:00:00","2015-07-31t00:00:00","2015-08-03t00:00:00","2015-08-04t00:00:00","2015-08-05t00:00:00","2015-08-06t00:00:00","2015-08-07t00:00:00","2015-08-10t00:00:00","2015-08-11t00:00:00","2015-08-12t00:00:00","2015-08-13t00:00:00","2015-08-14t00:00:00","2015-08-17t00:00:00","2015-08-18t00:00:00","2015-08-19t00:00:00"],"meta":{"start":"","end":"","totalresults":21,"offset":null,"limit":null,"fields":"","arguments":{}}} 

i try this:

 inp.datepicker({                             dateformat: dateformat,                             changemonth: true,                             //url: "/qmatic/getavailabledates/",                             type: "get",                                                        datatype: "application/json",                             url: "~/getavailabledates, qmatic",                             data:"{}",                              beforeshowday: function (date) {                                 var result = msg.d;                                  var array = []; //$.getjson("/qmatic/getavailabledates");  //["2015-03-14", "2015-03-15", "2015-03-16"];                                 var len = result.length;                                 (var = 0; < len; i++) {                                     array.push(result[i]);                                  }                                 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"                          }) 


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -