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

Invalid date when setting both startAttribute and endAttribute #94

Closed ghost closed 6 years ago

ghost commented 7 years ago

This is an example code:

echo DateRangePicker::widget([ 'name' => 'date_range', 'attribute' => 'datetime_range', 'startAttribute' => 'startDate', 'endAttribute' => 'endDate' ]);

If both startAttribute and endAttribute are set then the picker goes nuts: alt text

kartik-v commented 7 years ago

Debug your code and your data. You should have a valid date value of the correct format set in your 2 range attributes. The format must match the plugin format set. Else your date range will get broken.

CTOlet commented 7 years ago

Same problem. It raises only if startAttribute and endAttribute setted and it concatenates two empty strings with separator

giovaz94 commented 6 years ago

@sebascar if you're using your widget without a model you can simply insert 'locale' to your pluginOptions configuration like this:

'pluginOptions' => [ 'locale' => [ 'format' => 'd-m-Y' ], ],

If then you use a model and startAttribute/endAttribute are propeties (field) of that model you can resolve this issue with the DateRangeBehavior.

`
public $createTimeRange; public $createTimeStart; public $createTimeEnd;

/**
 * @inheritdoc
 */
public function behaviors()
{
    return [
        [
            'class' => DateRangeBehavior::className(),
            'attribute' => 'createTimeRange',
            'dateStartAttribute' => 'createTimeStart',
            'dateEndAttribute' => 'createTimeEnd',
            'dateStartFormat' => 'Y-m-d',
            'dateEndFormat' => 'Y-m-d'
        ],
    ];
}`

this should resolve your issue