JQuery Datepicker in Yii2
- By Preneesh AV --
- 09-Feb-2018 --
- 35 Comments
Simple implementation guide for jquery datepicker in yii2 framework.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js">
</script><script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<?php $form = ActiveForm::begin([
id' => 'addcampaign',
'options' => [
'class' => 'row',
'autocomplete'=>'off'
]
]); ?>
<?= $form->field($data, 'CampaignEndDate')
->textInput(['autofocus' => true, 'class' => 'form-control', 'placeholder' => "Enter Start Date",'required'=>true,'maxlength'=>200])
->label(false)
?>
<?php ActiveForm::end(); ?>
</body>
</html>
<?php
$js =" $(document).ready(function()
{
$( '#campaigns-campaignenddate').datepicker({ dateFormat: "dd-mm-yy" }).val();
}
);
";
$this->registerJs($js);
?>
