javascript - Bootstrap datetime picker disable hours -


i using bootsrap 3 datetime picker. find documentation doesn't how disable/enable hours, says this:

disabledhours

default: false

does how declare disabled hour? format?. need disable different hours weekdays , weekends.

you use workaround using ajax :

html :

<div class="form-group">     <div class="input-group bootstrap-timepicker">       <span>pick delivery time :</span>       <input id="datepicker" data-format="dd/mm/yyyy - h:mm" name="delivery_time" type="text" class="form-control input-small">     </div> </div> 

js :

$('#datepicker').on('dp.change', function(e) {     $.ajax({         cache: false,         datatype: 'json',         type: 'post',         data: 'theday='+json.stringify(e.date._d),         url: 'ajax/disable_hours.php',         success: function(data) {             if (data.return == true) {                 $('#datepicker').data('datetimepicker').enabledhours(                     data.allowed_hours                 );             } else {                 console.log(data);             }         },         error: function(jqxhr, textstatus, errorthrown) {             console.log(textstatus, errorthrown);         }     }); }); 

php :

// picked weekday js $theday = $_post['theday']; // value of last picked date (js: .e.date._d) $theday = substr($theday, 1,10); // isolate yyyy-mm-dd $theday = strtotime($theday); // make timestamp $theday = getdate($theday); // create date info array  // set opening hours $allowed_times = array(     'mondayopen'      => 8,     'mondayclose'     => 18,     'tuesdayopen'     => 8,     'tuesdayclose'    => 18,     'wednesdayopen'   => 10,     'wednesdayclose'  => 16,     'thursdayopen'    => 8,     'thursdayclose'   => 18,     'fridayopen'      => 8,     'fridayclose'     => 18,     'saturdayopen'    => 9,     'saturdayclose'   => 12,     'sundayopen'      => 9,     'sundayclose'     => 12 );  // useful variables $allowhours = array();  // set enabled hours arrays switch ($theday['wday']) {      // sunday     case 0:         $open = $allowed_times['sundayopen'];         $close = $allowed_times['sundayclose'];          $allowhours = array();         ($i = $open; $i < $close; $i++) {             array_push($allowhours, $i);         }          die(json_encode(array("return" => true, "allowed_hours" => $allowhours)));      // monday     case 1:         $open = $allowed_times['mondayopen'];         $close = $allowed_times['mondayclose'];          $allowhours = array();         ($i = $open; $i < $close; $i++) {             array_push($allowhours, $i);         }          die(json_encode(array("return" => true, "allowed_hours" => $allowhours)));      // tuesday     case 2:         $open = $allowed_times['tuesdayopen'];         $close = $allowed_times['tuesdayclose'];          $allowhours = array();         ($i = $open; $i < $close; $i++) {             array_push($allowhours, $i);         }          die(json_encode(array("return" => true, "allowed_hours" => $allowhours)));      // wednesday     case 3:         $open = $allowed_times['wednesdayopen'];         $close = $allowed_times['wednesdayclose'];          $allowhours = array();         ($i = $open; $i < $close; $i++) {             array_push($allowhours, $i);         }          die(json_encode(array("return" => true, "allowed_hours" => $allowhours)));      // thursday     case 4:         $open = $allowed_times['thursdayopen'];         $close = $allowed_times['thursdayclose'];          $allowhours = array();         ($i = $open; $i < $close; $i++) {             array_push($allowhours, $i);         }          die(json_encode(array("return" => true, "allowed_hours" => $allowhours)));      // friday     case 5:         $open = $allowed_times['fridayopen'];         $close = $allowed_times['fridayclose'];          $allowhours = array();         ($i = $open; $i < $close; $i++) {             array_push($allowhours, $i);         }          die(json_encode(array("return" => true, "allowed_hours" => $allowhours)));      // saturday     case 6:         $open = $allowed_times['saturdayopen'];         $close = $allowed_times['saturdayclose'];          $allowhours = array();         ($i = $open; $i < $close; $i++) {             array_push($allowhours, $i);         }          die(json_encode(array("return" => true, "allowed_hours" => $allowhours))); } 

there better out there maybe some.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -