kartik-v / yii2-date-range

A Date Range Picker for Bootstrap useful for reports and filtering.
http://demos.krajee.com/date-range
Other
93 stars 81 forks source link

DateRangePicker displays the wrong year data #57

Closed jonua closed 8 years ago

jonua commented 8 years ago

My code is:

<?= $form->field($dateFilter, 'range', [
            'options' => [
                'style' => 'width: 200px',
            ]
        ])->widget(DateRangePicker::className(), [
            'model' => $dateFilter,
            'attribute' => 'range',
            'presetDropdown' => false,
            'initRangeExpr' => true,
            'pluginOptions' => [
                'format' => 'YYYY-MM-DD',
            ],
            'pluginEvents' => [
                "apply.daterangepicker" => "function() { $('#timeline-filterModel-form').submit(); }",
            ],
        ]) ?>

and I see the next daterangepicker: c

(year as 000n)

cicsolutions commented 8 years ago

I too am experiencing similar behavior. As in your screenshot, the dates next to the calendar icons are showing as "invalid date" for me too.

If I figure anything out, I'll let you know!

cicsolutions commented 8 years ago

I was able to fix this issue by setting the date format. There may be a couple ways to do this, but I did it like this ...

'pluginOptions' => [
    'locale' => ['format' => 'm/d/Y'],
],
kartik-v commented 8 years ago

@kdjonua you may want to read the plugin documentation for plugin options supported. There is no format property within pluginOptions that can be read by the plugin.

It is pluginOptions['locale']['format'].

Note the widget also allows you to set a PHP Date Format in pluginOptions['locale']['format'] when convertFormat property is set to true- and by this the widget will auto convert it to javascript (moment lib) date format.

If you wish to use JS moment date format instead - then set convertFormat to false and proceed