0

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> &nbsp;<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?

2

3 Answers 3

1

You can use yii 2 form and model

field($model, 'from_date')->widget(\yii\jui\DatePicker::classname(), [ //'language' => 'ru', //'dateFormat' => 'yyyy-MM-dd', ]) ?>
Sign up to request clarification or add additional context in comments.

Comments

0

First you need to register jquery file and jquery.ui file

$this->registerJsFile(
  '@web/js/jquery.ui.min.js',
  ['depends' => [\yii\web\JqueryAsset::className()]]
);

Comments

0

Register your script like below in your form

use yii\web\View;

 <?php
    $script = <<< JS
    $('#datepicker').datepicker();
    JS;
    $this->registerJs($script, View::POS_END);
 ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.