Giter Club home page Giter Club logo

yii2-date-range's Introduction

Krajee Logo
yii2-date-range
Donate

Stable Version Untable Version License Total Downloads Monthly Downloads Daily Downloads

An advanced date range picker input for Yii Framework 2 based on dangrossman/bootstrap-daterangepicker plugin. The date range picker widget is styled for Bootstrap 3.x and 4.x versions and creates a dropdown menu from which a user can select a range of dates. If the plugin is invoked with no options, it will present two calendars to choose a start and end date from. Optionally, you can provide a list of date ranges the user can select from instead of choosing dates from the calendars. If attached to a text input, the selected dates will be inserted into the text box. Otherwise, you can provide a custom callback function to receive the selection.

Additional enhancements added for this widget (by Krajee):

  • allows ability to work with Bootstrap input group addons and set the picker position to point at the input-group-addon icon.
  • enhanced translation features using yii i18n message files.
  • automatically convert format from PHP Date/time format to Moment.js Date/time format.
  • automatically trigger change of base field to enforce Yii ActiveField validation
  • ability to set the widget to display a preset dropdown of date options within a container (and hidden input).
  • style the container options as per your need using templates
  • automatically disable date-range based on disabled/readonly options.

Demo

You can see detailed documentation on usage of the extension.

Release Changes

Refer the CHANGE LOG for details of various releases.

Installation

The preferred way to install this extension is through composer.

Note: Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

Either run

$ php composer.phar require kartik-v/yii2-date-range "dev-master"

or add

"kartik-v/yii2-date-range": "dev-master"

to the require section of your composer.json file.

Usage

DateRangePicker

use kartik\daterange\DateRangePicker;
echo DateRangePicker::widget([
    'model'=>$model,
    'attribute'=>'datetime_range',
    'convertFormat'=>true,
    'pluginOptions'=>[
        'timePicker'=>true,
        'timePickerIncrement'=>30,
        'locale'=>[
            'format'=>'Y-m-d h:i A'
        ]
    ]
]);

or using seperate min/max attributes on model

use kartik\daterange\DateRangePicker;
echo DateRangePicker::widget([
    'model'=>$model,
    'attribute'=>'datetime_range',
    'convertFormat'=>true,
    'startAttribute'=>'datetime_min',
    'endAttribute'=>'datetime_max',
    'pluginOptions'=>[
        'timePicker'=>true,
        'timePickerIncrement'=>30,
        'locale'=>[
            'format'=>'Y-m-d h:i A'
        ]
    ]
]);

DateRangeBehavior

use kartik\daterange\DateRangeBehavior;

class UserSearch extends User
{
    public $createTimeRange;
    public $createTimeStart;
    public $createTimeEnd;

    public function behaviors()
    {
        return [
            [
                'class' => DateRangeBehavior::className(),
                'attribute' => 'createTimeRange',
                'dateStartAttribute' => 'createTimeStart',
                'dateEndAttribute' => 'createTimeEnd',
            ]
        ];
    }

    public function rules()
    {
        return [
            // ...
            [['createTimeRange'], 'match', 'pattern' => '/^.+\s\-\s.+$/'],
        ];
    }

    public function search($params)
    {
        $query = User::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
        $this->load($params);
        if (!$this->validate()) {
            $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere(['>=', 'createdAt', $this->createTimeStart])
              ->andFilterWhere(['<', 'createdAt', $this->createTimeEnd]);

        return $dataProvider;
    }
}

License

yii2-date-range is released under the BSD-3-Clause License. See the bundled LICENSE.md for details.

yii2-date-range's People

Contributors

64bitint avatar andredp avatar anothersoftware-lv avatar daixianceng avatar dogrocker avatar edofre avatar ekawalec avatar fedemotta avatar fsateler avatar githubjeka avatar gitnchez avatar gvasilopulos avatar karataserkan avatar kartik-v avatar kenjebaev avatar kksudo avatar leandrogehlen avatar lourdas avatar madand avatar mikk150 avatar mingchi21 avatar nathanramli avatar odilov-sh avatar pc-brainy avatar s1lver avatar samkoch avatar talkitron avatar tibee avatar torvaldz avatar tranch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-date-range's Issues

Bootstrap Daterangepicker outdated

Would be great to drop embed daterangepicker.js and moment.js in favour of composer dependencies. I am curretly stuck with some features wich are present in current daterangepicker v2 while plugin in shipped with outdated v1.

Correct code for PHP 5.5

After last update I've got an error:

Can't use method return value in write context

1. in /projects/php/project1/vendor/kartik-v/yii2-date-range/DateRangePicker.php at line 480
471472473474475476477478479480481482483484485486487488489
    /**
     * Generates and returns the client script on date range change, when the start and end attributes are set
     *
     * @param string $type whether `start` or `end`
     *
     * @return string
     */
    protected function getRangeJs($type = '')
    {
        if (empty($this->getRangeAttr($type))) {
            return '';
        }
        $options = $this->getInputOpts($type);
        $input = "jQuery('#" . $this->options['id'] . "')";
        return "var v={$input}.val() ? {$type}.format('{$this->_format}') : '';jQuery('#" . $options['id'] .
        "').val(v).trigger('change');";
    }

    /**

The problem due to the fact that since php 5.5, function is invalid value for empty() function:

Note:
Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

Please change getRangeJs() in DateRangePicker.php

From:

protected function getRangeJs($type = '')
{
    if (empty($this->getRangeAttr($type))) {
        return '';
    }
    $options = $this->getInputOpts($type);
    $input = "jQuery('#" . $this->options['id'] . "')";
    return "var v={$input}.val() ? {$type}.format('{$this->_format}') : '';jQuery('#" . $options['id'] .
    "').val(v).trigger('change');";
}

To:

protected function getRangeJs($type = '')
{
    $rangeAttr = $this->getRangeAttr($type);
    if (empty($rangeAttr)) {
        return '';
    }
    $options = $this->getInputOpts($type);
    $input = "jQuery('#" . $this->options['id'] . "')";
    return "var v={$input}.val() ? {$type}.format('{$this->_format}') : '';jQuery('#" . $options['id'] .
    "').val(v).trigger('change');";
}

Clicking "today" the first time on an empty field doesn't fill it

http://demos.krajee.com/date-range
The trouble is visible on your example. There is an empty daterange field configured with dropdown format. If you click it and choose "Today" nothing happens. You need to choose something else first to choose "today" or have not empty but rather today as a default value.

It seems the problem exists because the plugin does not support emptiness though your widget still tries to support it. I think internally the plugin is already at "Today" and that's why you can't make it "Today" again. Not supporting emptiness is sad because that way you can't use the widget for filtering the grid.

Multiple usage in one page and "apply.daterangepicker" event

Hi

I use this nice widget twice on my view, but only once render on(.apply.daterangepicker javascript code. Hm.. what's wrong?

<?=DateRangePicker::widget([
                'options'=>['id'=>'one'],
                'name'=>'studentrange',
                'convertFormat'=>true,
                'pluginOptions'=>[
                    'id'=>'one',
                    'locale'=>['format'=>'Y/m/d'],
                    'separator'=>'-',
                ],
                'pluginEvents'=>[
                    "apply.daterangepicker"=>"function(){ $('#filter').submit(); }",
                ]
            ]);?>
<?=DateRangePicker::widget([
                'options'=>['id'=>'two'],
                'name'=>'teacherrange',
                'convertFormat'=>true,
                'pluginOptions'=>[
                    'id'=>'two',
                    'locale'=>['format'=>'Y/m/d'],
                    'separator'=>'-',
                ],
                'pluginEvents'=>[
                    "apply.daterangepicker"=>"function(){ $('#filter').submit(); }",
                ]
            ]);?>
jQuery(document).ready(function () {
if (jQuery('#w1').data('daterangepicker')) { jQuery('#w1').daterangepicker('destroy'); }
jQuery("#w1").daterangepicker(daterangepicker_5675aeba, function(start,end,label){var val=start.format('YYYY/MM/DD') + ' - ' + end.format('YYYY/MM/DD');jQuery("#w1").val(val);jQuery("#w1").trigger('change');});
jQuery("#w1").on('apply.daterangepicker', function(){ $('#filter').submit(); });

if (jQuery('#w2').data('daterangepicker')) { jQuery('#w2').daterangepicker('destroy'); }
jQuery("#w2").daterangepicker(daterangepicker_5ca83dc4, function(start,end,label){var val=start.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD');jQuery("#w2").val(val);jQuery("#w2").trigger('change');});

jQuery(document).pjax("#w0 a", "#w0", {"push":true,"replace":false,"timeout":1000,"scrollTo":false});
jQuery(document).on('submit', "#w0 form[data-pjax]", function (event) {jQuery.pjax.submit(event, '#w0', {"push":true,"replace":false,"timeout":1000,"scrollTo":false});});
$(function () {
    $("[data-toggle='tooltip']").tooltip();
});;
$(function () {
    $("[data-toggle='popover']").popover();
});
});
``

Provide 2 attributes to set start and end dates

Hello, to make this extension easy to use, please provide the ability to set 2 attributes. Currently, as I understand reading the documentation, you can only set one attribute from a model, and when you want to actually use the selected dates, you have to extract them for yourself using ugly string handling.

It would be way better if you could set 2 attributes, just as you can do with your other extension yii2-field-range:

echo FieldRange::widget([
    'form' => $form,
    'model' => $model,
    'label' => 'Enter date range',
    'attribute1' => 'begin_date',
    'attribute2' => 'end_date',
    'type' => FieldRange::INPUT_DATE,
]);

Can't overwrite $this->pluginOptions['ranges']

It is impossible to overwrite $this->pluginOptions['ranges'] options. There should be range value check:

right now there is:

  $this->pluginOptions['ranges'] = [
                Yii::t('kvdrp', "Today") => ["moment().startOf('day')", "moment()"],
                Yii::t('kvdrp', "Yesterday") => [
                    "moment().startOf('day').subtract(1,'days')",
                    "moment().endOf('day').subtract(1,'days')"
                ],
                Yii::t('kvdrp', "Last {n} Days", ['n' => 7]) => [
                    "moment().startOf('day').subtract(6, 'days')",
                    "moment()"
                ],
                Yii::t('kvdrp', "Last {n} Days", ['n' => 30]) => [
                    "moment().startOf('day').subtract(29, 'days')",
                    "moment()"
                ],
                Yii::t('kvdrp', "This Month") => ["moment().startOf('month')", "moment().endOf('month')"],
                Yii::t('kvdrp', "Last Month") => [
                    "moment().subtract(1, 'month').startOf('month')",
                    "moment().subtract(1, 'month').endOf('month')"
                ],
            ];

should be:

if(!isset($this->pluginOptions['ranges'])){
    $this->pluginOptions['ranges'] = [
                Yii::t('kvdrp', "Today") => ["moment().startOf('day')", "moment()"],
                Yii::t('kvdrp', "Yesterday") => [
                    "moment().startOf('day').subtract(1,'days')",
                    "moment().endOf('day').subtract(1,'days')"
                ],
                Yii::t('kvdrp', "Last {n} Days", ['n' => 7]) => [
                    "moment().startOf('day').subtract(6, 'days')",
                    "moment()"
                ],
                Yii::t('kvdrp', "Last {n} Days", ['n' => 30]) => [
                    "moment().startOf('day').subtract(29, 'days')",
                    "moment()"
                ],
                Yii::t('kvdrp', "This Month") => ["moment().startOf('month')", "moment().endOf('month')"],
                Yii::t('kvdrp', "Last Month") => [
                    "moment().subtract(1, 'month').startOf('month')",
                    "moment().subtract(1, 'month').endOf('month')"
                ],
            ];
}

Infinite refresh of grid view after last update

After updating to v1.6.4 my grid view is refreshing infinitely. I use daterangepicker as a filter for datetime column. Default filter value is empty, but after page load some value is inserted into filter input and grid form is submitted.

Cannot select end date earlier than current date

The datepicker will not display a left arrow to select an end date earlier than the current date.

Deployed like this:

$datepicker = DateRangePicker::widget([
'name'=>'DownloadHistorySearch[download_datetime]',
'convertFormat'=>true,
'pluginOptions'=>[
    'timePicker'=>false,
    'format'=>'d-m-Y',
    'opens'=>'left'
]            
]);

DateRangePicker displays the wrong year data

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)

I want to help with Russian translation :)

return [
    'Today'=>'Сегодня',
    'Yesterday'=>'Вчера',
    'Last {n} Days'=>'Последние {n} дней',
    'This Month'=>'Этот месяц',
    'Last Month'=>'Прошлый месяц',
    // Demo Data
    'Select Date Range'=>'Выберите диапазон дат'
];

yii.js data-method action not working on plugin load

On loading plugin the yii.js data-method listeners no longer work.
in DateRangerPickerAsset, on setting up js/daterangepicker asset, the yii.js action fails

 public function init()
  {
       $this->setSourcePath(__DIR__ . '/assets');
       $this->setupAssets('css', ['css/daterangepicker', 'css/daterangepicker-kv']);
       $this->setupAssets('js', ['js/daterangepicker']);
       parent::init();
   }

Estonian translation for kvdrp.php

return [
    'Apply' => 'Sisesta',
    'Cancel' => 'Tühista',
    'Custom Range' => 'Vaba valik',
    'From' => 'Alates',
    'Last Month' => 'Eelmine kuu',
    'Last {n} Days' => 'Viimased {n} päeva',
    'Select Date Range' => 'Vali kuupäevade vahemik',
    'This Month' => 'Käesolev kuu',
    'To' => 'Kuni',
    'Today' => 'Täna',
    'W' => 'N',
    'Yesterday' => 'Eile',
];

'Drops' functionality not working

In the 1.3.20 and 1.3.21 release of bootstrap-daterangepicker there is a new functionality called drop (and later drops) to show the calendar above the input. I see that yii2-date-range it is outdated (version 1.3.17) so this functionality it is not working.

LanguageAsset doesn't get baseUrl

kartik\daterange\LanguageAsset does not get baseUrl, so when its loaded to the browser it appears like <script src="/js/locales/pt-BR.js"></script>

Using 'addon' property overrides populated format

The following deployment populates the form element with 'Y-m-d' as expected

<?= $form->field($model, 'date_published', [
               //'addon'=>['prepend'=>['content'=>'<i class="glyphicon glyphicon-calendar"></i>']],
                'options'=>['class'=>'form-group field-page-date_published']
            ])->widget(DateRangePicker::classname(), [
               // 'useWithAddon'=>true,
                'convertFormat'=>true,
                'pluginOptions'=>[
                    'timePicker'=>false,
                    'format'=>'Y-m-d',
                    'singleDatePicker'=>true,
                    'showDropdowns'=>true
                ] ]);
    ?>

...but if one uncomments the two lines to use the addon property, the form element is populated with 'Y-m-d - Y-m-d'. I realise that this is a DateRange picker, not a Date picker, but this still seems to me to look like a bug.

startAttribute and endAttribute configuration ignored

Hi,
i am getting the following error
Setting unknown property: <ModelNameHere>::startAttribute
with startAttribute and endAttribute configured like this

'startAttribute' => 'fiscalYearBegin',
'endAttribute' => 'fiscalYearEnd',

I traced the error to lines 484 of the DateRangePicker.php:

protected function initRangeValue($type = '', $value = '')
    {
        $attr = $type . 'Attribute';
        if (!$this->$attr || empty($value)) {
            return;
        }
        if ($this->hasModel()) {
            $this->model->$attr = $value;
        } else {
            $opts = $type . 'InputOptions';
            $options = $this->$opts;
            $options['value'] = $value;
            $this->$opts = $options;
        }
    }

So. As far as i understand it $attr is either "startAttribute" or "endAttribute". Both are public properties within the DateRangePicker. But in line 491
$this->model->$attr = $value;
the model is expected to have properties named exactly like that, ignoring the configuration and content of the widgets properties.
My guess is it should read:
$this->model->{$this->$attr} = $value;
... at least that works for me.

Cheers Kai

Option to clear

Hey,

Your date-range have any option for the user clear the field ?

This is my config:

  $form->field($task_event, 'search_date_range', [
      'options'=>['class'=>'drp-container form-group']
  ])->widget(DateRangePicker::classname(), [
      'useWithAddon'=>true,
      'hideInput'=>true,
      'language' => 'pt-BR'
  ]);

DateRangePicker cannot be found

I have the DateRangePicker in my vendors folder and I have the use statement in my code and I am getting this error ...

exception 'yii\base\ErrorException' with message 'Class 'kartik\daterange\DateRangePicker' not found'

Any ideas why?

Asset registration order issue using in GridView

Hi, I'm finding the JS assets are rendered in the wrong order when using FILTER_DATE_RANGE column in your GridView - can't see why this is happening after a good look at the code and comparing to DatePicker code flow for asset registration

Latest version of everything.
CustomGridView extends Kartik GridView

class CustomGridView extends \kartik\grid\GridView{

    public function init()
    {

        parent::init();
        $this->export = false;
    }


    public function run(){
        return parent::run();
    }

    public function registerAssets()
    {
        parent::registerAssets();
    }

}

View filter snippet

    <?php \yii\widgets\Pjax::begin(['linkSelector' => '[data-sort],[data-page]']); ?>
    <?= CustomGridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel, 'showHeader' => $showHeader,
        'filterPosition' => $filterPosition,
        'formatter' => ['class' => 'yii\i18n\Formatter', 'nullDisplay' => ''],
        'columns' => $columns
    ]); ?>
    <?php \yii\widgets\Pjax::end(); ?>

columns snippet:

            [
                'filterType'=>CustomGridView::FILTER_DATE_RANGE,
                'attribute' => 'search_date',
                'label' => 'Date',
                'headerOptions' => ['class' => 'pager-date-column'],
                'format' => 'date',
                'filterWidgetOptions'=>[
                    'pluginOptions' => [
                    ]
                ]
            ],

Rendered page JS, yii.gridView.js is included before jquery.js, no yii.js

<script src="/assets/b90ee649/yii.gridView.js?v=1431288587"></script>
<script src="/assets/84597792/js/daterangepicker.js?v=1435631484"></script>
<script src="/assets/7329f298/jquery.pjax.js?v=1432264189"></script>
<script src="/assets/65a6fa36/jquery.js?v=1430236984"></script>
<script src="/assets/cf374a95/jquery-ui.js?v=1432264189"></script>
<script src="/assets/e97f2b3/js/bootstrap.js?v=1434471202"></script>
<script src="/assets/768646cf/jquery.slimscroll.js?v=1432264189"></script>
<script src="/assets/57a98a69/js/app.js?v=1432264194"></script>
<script src="/assets/3ae58f8a/dist/html5shiv.min.js?v=1432264189"></script>
<script src="/assets/89aab66e/fuelux/js/fuelux.min.js?v=1432264193"></script>
<script src="http://men.dev//js/lodash.min.js?v=1432264186"></script>
<script src="http://men.dev//js/moment.min.js?v=1432264186"></script>
<script src="http://men.dev//js/bootbox.min.js?v=1432264186"></script>
<script src="http://men.dev//js/app.js?v=1436432407"></script>
<script src="http://men.dev//js/plugins.js?v=1435692606"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/q.js/1.2.0/q.min.js"></script>
<script src="/assets/ca468c97/subscription_dashboard.js?v=1433899806"></script>
<script src="/assets/9a1b013d/admin.js?v=1435875900"></script>
<script type="text/javascript">window.App.currentUser ={ id: 1  };</script>
<script type="text/javascript">jQuery(document).ready(function () {
jQuery('#w1').yiiGridView({"filterUrl":"\/admin\/user\/2\/subscriptions\/1\/transactions","filterSelector":"#w1-filters input, #w1-filters select"});
jQuery("#subscriptiontransactionsearch-search_date").daterangepicker(daterangepicker_2bc54c98);

Works fine for FILTER_DATE

            [
                'filterType'=>CustomGridView::FILTER_DATE,
                'attribute' => 'search_date',
                'label' => 'Date',
                'headerOptions' => ['class' => 'pager-date-column'],
                'format' => 'date',
                'filterWidgetOptions'=>[
                    'pluginOptions' => [
                    ]
                ]
            ],

Correct JS order

</script><script src="/assets/65a6fa36/jquery.js?v=1430236984"></script>
<script src="/assets/b90ee649/yii.js?v=1431288587"></script>
<script src="/assets/b90ee649/yii.gridView.js?v=1431288587"></script>
<script src="/assets/4b3889f0/js/bootstrap-datepicker.js?v=1435632223"></script>
<script src="/assets/4b3889f0/js/datepicker-kv.js?v=1435632223"></script>
<script src="/assets/7329f298/jquery.pjax.js?v=1432264189"></script>
<script src="/assets/cf374a95/jquery-ui.js?v=1432264189"></script>
<script src="/assets/e97f2b3/js/bootstrap.js?v=1434471202"></script>
<script src="/assets/768646cf/jquery.slimscroll.js?v=1432264189"></script>
<script src="/assets/57a98a69/js/app.js?v=1432264194"></script>
<script src="/assets/3ae58f8a/dist/html5shiv.min.js?v=1432264189"></script>
<script src="/assets/89aab66e/fuelux/js/fuelux.min.js?v=1432264193"></script>
<script src="http://men.dev//js/lodash.min.js?v=1432264186"></script>
<script src="http://men.dev//js/moment.min.js?v=1432264186"></script>
<script src="http://men.dev//js/bootbox.min.js?v=1432264186"></script>
<script src="http://men.dev//js/app.js?v=1436432407"></script>
<script src="http://men.dev//js/plugins.js?v=1435692606"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/q.js/1.2.0/q.min.js"></script>
<script src="/assets/ca468c97/subscription_dashboard.js?v=1433899806"></script>
<script src="/assets/9a1b013d/admin.js?v=1435875900"></script>
<script type="text/javascript">window.App.currentUser ={ id: 1  };</script>
<script type="text/javascript">jQuery(document).ready(function () {
jQuery('#w1').yiiGridView({"filterUrl":"\/admin\/user\/2\/subscriptions\/1\/transactions","filterSelector":"#w1-filters input, #w1-filters select"});
jQuery('#subscriptiontransactionsearch-search_date').parent().kvDatepicker(kvDatepicker_00000000);

Use the yii2-date-ranger in yii2-grid drop in loop to load the page with new version(v1.6.7)

I use the DateRangerPick like this as a column :
[ 'attribute' => 'time', 'format' => ['date','php:Y-m-d'], //'class' => 'kartik\daterange\DateRangePiker' 'filterType' => GridView::FILTER_DATE_RANGE, 'filterWidgetOptions' => [ 'presetDropdown' => true, 'pluginOptions' => [ 'locale' => [ 'separator' => ' to ', 'format' => 'YYYY-MM-DD', ], ], ], ],
with old version, it work good, but for today have little problem.
when i upgrade for new version(v1.6.7).
I found the page drop into loop like:
get this request: http://127.0.0.1:8080/index.php?DeliverySearch%5Btime%5D=03%2F15%2F2016+-+03%2F15%2F2016&DeliverySearch%5Bcustomer_id%5D=&DeliverySearch%5BdetailCount%5D=&DeliverySearch%5Bmoney%5D=&DeliverySearch%5Bprofit%5D=&r=delivery%2Findex

The Web Console show this error:
VM124 index.php?DeliverySearch[time]=03%2F15%2F2016+-+03%2F15%2F2016&DeliverySearch[customer_id]=&D…:30 Uncaught TypeError: moment.weekdaysStart is not a function

The Source locate in this:
var kvGridExp_df43f813={"gridOpts":kvGridExp_16f6c083,"genOpts":kvGridExp_383dfdd3,"alertMsg":"将会导出JSON文件以供下载","config":{"colHeads":[],"slugColHeads":false,"jsonReplacer":function(k,v){return typeof(v)==='string'?$.trim(v):v},"indentSpace":4}}

So. what i could do for it? Downgrade?Thanks You for your patience!

Please close it, I found the resolve in the pull request. the weekdaysStart is wrong by weekdaysShort

minDate and maxDate pluginOptions not working

I'm trying to get the minDate and maxDate pluginOptions to work to limit the times the user is able to select. I would like the user to be able to select and time between now and 14 days in the future. Here is my code:

field($model, 'daterange', [ 'addon'=>['prepend'=>['content'=>'']], 'options'=>['class'=>'drp-container form-group'] ])->widget(DateRangePicker::classname(), [ 'useWithAddon'=>true, 'convertFormat' => true, 'pluginOptions' => [ 'timePicker' => true, 'timePickerIncrement' => 15, 'timePicker12Hour' => false, 'separator' => ' to ', 'minDate' => 'moment()', 'maxDate' => "moment().startOf('day').add(14,'days')", 'format' => 'Y-m-d h:i A'] ]); ?>

Without the 'minDate' and 'maxDate' options, everything works, with them on, I cannot select any days and can only go back into the past.

Bug on kartik\yii2-grid with PJAX

Hello,

I trie used this daterange on filter with ModelSearch, but when i set PJAX true and clicking on the date field does not open the menu.

How to reproduce:

use kartik\grid\GridView;
use kartik\daterange\DateRangePicker;

...

                         [
                            'label' => Yii::t('app', "Confirmation Date"),
                            'attribute' => 'confirmation_date',
                            'value' => 'confirmation_date',
                            'format' => 'date',
                            'filter' => DateRangePicker::widget([
                                'model' => $searchModel,
                                'language' => 'es',
                                'attribute' => 'confirmation_date',
                                'convertFormat' => true,
                                'presetDropdown' => true,
                                'pluginOptions' => [
                                    'locale' => [
                                        'format' => 'Y-m-d',
                                    ],
                                ],
                            ]),
                        ],

...

'pjax'=>true,

Version

kartik-v/yii2-date-range (dev-master 70febdb)
Checking out 70febdb

DateRangePicker has problems with assets

after init DateRangePicker Exception "An asset bundle that depends on 'yii\web\JqueryAsset' has a higher javascript file position configured than 'yii\web\JqueryAsset'."

helped deleting a row jsOptions

class LanguageAsset extends AssetBundle
{
// public $jsOptions = ['position' => \yii\web\View::POS_HEAD];

/**
 * @inheritdoc
 */
public function init()
{
    $this->depends = array_merge($this->depends, ['\kartik\daterange\MomentAsset']);
    $this->setSourcePath(__DIR__ . '/assets');
    parent::init();
}

}

jquery failed

I'm getting this error and because of that the date range is not working.

TypeError: jQuery(...).daterangepicker is not a function

DateRange as GridView filter disappears after pjax request

I have an Invoice model (with its InvoiceSearch one extending it) having a delivery_date field. I'm trying to use the DateRangePicker widget to filter my yii\grid\GridView.
DateRangePicker configuration is:

$daterange = [
    'model' => $invoiceSearch,
    'attribute' => 'delivery_date',
    'convertFormat' => false,
    'pluginOptions' => [
        'format' => 'YYYY-MM-DD',
    ],
];

so I use it in my column definition:

[...]
[
    'attribute' => 'delivery_date',
    'filter' => DateRangePicker::widget($daterange),
],
[...]

Widget works only the first time (i.e. calendar appears and after date selection the pjax request starts), but after the response replaces the grid view with the filtered one, date range picker is no more shown. Inspecting the pjax response, there is no new daterangepicker_<hash> inside the html, while the input field has a new config data reference instead.

P.S.: if I replace config with this:

$daterange = [
    'model' => $invoiceSearch,
    'attribute' => 'delivery_date',
    'convertFormat' => true,
    'pluginOptions' => [
        'format' => 'php:Y-m-d',
    ],
];

widget dates are not correctly parsed and appear like this: p12p:2015-08-18 instead of 2015-08-18 (always disappearing after the first request as before).

Do I miss something?

Using ranges and alwaysShowCalendars

Hello

I am using the DateRangePicker widget in an activeform, working great except when I want to display the ranges while still displaying the calendars. The setting "alwaysShowCalendars" doesn't have any effect.

This example is working as expected displaying the calendars and no ranges:

<?php
echo $form->field( $model, 'date_range', [
'options' => [ 'class'=>'form-group', 'autocomplete' => 'off' ]
] )->widget( DateRangePicker::classname(), [
] );
?>

This example is not working as expected, only displaying the ranges, the "alwaysShowCalendars" setting should force calendars to be displayed:

<?php
echo $form->field( $model, 'date_range', [
'options' => [ 'class'=>'form-group', 'autocomplete' => 'off' ] 
] )->widget( DateRangePicker::classname(), [
    'pluginOptions' => [
        'ranges' => [
            Yii::t('kvdrp', "Today") => ["moment().startOf('day')", "moment()"],
            Yii::t('kvdrp', "Yesterday") => ["moment().startOf('day').subtract(1,'days')", "moment().endOf('day').subtract(1,'days')"],
            Yii::t('kvdrp', "Next {n} Days", ['n' => 7]) => ["moment()", "moment().startOf('day').add(6, 'days')"],
            Yii::t('kvdrp', "Last {n} Days", ['n' => 30]) => ["moment().startOf('day').subtract(29, 'days')", "moment()"],
            Yii::t('kvdrp', "This Month") => ["moment().startOf('month')", "moment().endOf('month')"],
            Yii::t('kvdrp', "Last Month") => ["moment().subtract(1, 'month').startOf('month')", "moment().subtract(1, 'month').endOf('month')"],
        ],
        'alwaysShowCalendars' => true,
    ]
] );
?>

I tried adding initRangeExpr=true and presetDropdown=true without success.

Is there something I need to know or a bug?
Thanks a lot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.