Speaktech.in

Yii2 widget datepicker set start date and end date

Provision to set up yii2 widget datepicker in activeform can be done using following codes. Kartik date picker also provide option to set start date and end date for selection.

Below code we have set start date to be current todays date and end date to be next day. Enabling the calender with selection for today and tomorrow.

$startDate= date('d/m/Y');
echo $form->field($model, 'OrderDate')
->widget(DatePicker::classname(), [
 'options' => [
 'value' => Yii::$app->formatter->asDate($startDate, 'dd-m-yyyy') ],
'type' => DatePicker::TYPE_INPUT,
'pluginOptions' => [
'startDate' => (string) $startDate,
'autoclose' => true,
'format' => 'dd-M-yyyy',
//'todayHighlight' => true,
"endDate" => (string) date('d/m/Y', time() + (1 * 24 * 60 * 60)),
],
'pluginEvents' => [
"change" => 'function()
  {
var data_id = $(this).val();
$.ajax({
type: "GET",
url: "'.\yii\helpers\Url::to(['orders/fetchslots']).'",
data: { dt: data_id },
success: function(data)
{
$("#orders-orderdeliveryslotid" ).html( data );
},
});
}', ],
])->label(false)
?>