Reputation: 173
I have used normal input field in Yii 2 to take a date. I haven't used model for input field. How can I use datepicker in that input field?
My code for input field is:
<div class="col-lg-4">
<label>From</label> <input type="text" id="datepicker" class="form- control" name="frominput" />
</div>
And now my JS code is:
<?php
$this->registerJs("
$( '#datepicker' ).datepicker();
");
?>
This doesn't show datepicker. How can I do this?
Upvotes: 0
Views: 1564
Reputation: 150
You can use yii 2 form and model
field($model, 'from_date')->widget(\yii\jui\DatePicker::classname(), [ //'language' => 'ru', //'dateFormat' => 'yyyy-MM-dd', ]) ?>Upvotes: 1
Reputation: 920
Register your script like below in your form
use yii\web\View;
<?php
$script = <<< JS
$('#datepicker').datepicker();
JS;
$this->registerJs($script, View::POS_END);
?>
Upvotes: 0
Reputation: 2455
First you need to register jquery file and jquery.ui file
$this->registerJsFile(
'@web/js/jquery.ui.min.js',
['depends' => [\yii\web\JqueryAsset::className()]]
);
Upvotes: 0