Jump to content

Month and Year in jui date picker are not fetched correctly on Update form


Recommended Posts

I am using jui datepicker. I have a table which has columns StartYear and EndYear set to varchar data type. I need to store the Start Year in the format of Month Year for example
Start Year : Jan 2023
End Year : Jan 2024

I have configured the jui date picker to show only Month and Year. Data is getting correctly saved in the table in create action, but on the update form the same data is not fetched correctly as shown in below image


Below is the code _form.php


use yii\helpers\Html;

use yii\bootstrap\ActiveForm;
use yii\jui\DatePicker;
use yii\helpers\ArrayHelper;
<style type="text/css">
.ui-datepicker-calendar {
        display: none;

$(document).ready(function() {
     changeMonth: true,
     changeYear: true,
     dateFormat: 'MM yy',

		 onClose: function() {
        var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
        $(this).datepicker('setDate', new Date(iYear, iMonth, 1));

 <?php $form = ActiveForm::begin();?>
<?= $form->field($model, 'StartYear')->widget(DatePicker::classname(), [
											//'language' => 'ru',

											'options' => ['class' => 'form-control picker','readOnly'=>'readOnly'],
											'dateFormat' => 'MM yy',

]) ?>

 <?= $form->field($model, 'EndYear')->widget(DatePicker::classname(), [
											//'language' => 'ru',
											'options' => ['class' => 'form-control picker','readOnly'=>'readOnly'],
											'dateFormat' => 'MM yy',
]) ?>
 <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
<?php ActiveForm::end(); ?>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.