Skip to content

Commit c6cb19d

Browse files
committed
Update to release v1.6.5 fixes #52
1 parent 8735830 commit c6cb19d

File tree

8 files changed

+104
-91
lines changed

8 files changed

+104
-91
lines changed

CHANGE.md

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
Version 1.6.4
2-
=============
1+
Change Log: `yii2-date-range`
2+
=============================
3+
4+
## Version 1.6.5
5+
6+
**Date:** 22-Oct-2015
7+
8+
- (enh #52): New property `autoUpdateOnInit` to prevent plugin triggering change due to `pluginOptions['autoUpdateInput']` default setting.
9+
- (enh #53): Added correct German translations.
10+
11+
## Version 1.6.4
12+
313
**Date:** 19-Oct-2015
414

515
- (enh #41): Add Simplified Chinese translations.
616
- (enh #43): Add Slovak translations.
7-
- (bug #45): Correct MomentAsset dependency.
8-
- (enh #46): Better defaulting of `form-control` CSS class.
9-
- (enh #50): Enhancement for single date picker plugin functionality.
1017
- (enh #51): Update to latest release of bootstrap-datarangepicker plugin.
1118

12-
Version 1.6.3
13-
=============
19+
## Version 1.6.3
20+
1421
**Date:** 22-May-2015
1522

1623
- (enh #31): Add Ukranian translations.
@@ -19,34 +26,34 @@ Version 1.6.3
1926
- (enh #38): Update to latest release of bootstrap-datarangepicker plugin.
2027
- (enh #40): Update moment library and locales.
2128

22-
Version 1.6.2
23-
=============
29+
## Version 1.6.2
30+
2431
**Date:** 02-Mar-2015
2532

2633
- (enh #27): Correct initial value initialization for all cases.
2734
- (enh #28): Upgrade to latest release of bootstrap-daterangepicker plugin.
2835
- Set copyright year to current.
2936
- (enh #29): Improve validation to retrieve the right translation messages folder.
3037

31-
Version 1.6.1
32-
=============
38+
## Version 1.6.1
39+
3340
**Date:** 16-Feb-2015
3441

3542
- (enh #27): Correct initial value initialization for all cases.
3643
- (enh #28): Upgrade to latest release of bootstrap-daterangepicker plugin.
3744
- Set copyright year to current.
3845

39-
Version 1.6.0
40-
=============
46+
## Version 1.6.0
47+
4148
**Date:** 12-Jan-2015
4249

4350
- (enh #22): Estonian translation for kvdrp.php
4451
- (enh #23): Russian translations updated.
4552
- Code formatting updates as per Yii2 standards.
4653
- Revamp to use new Krajee base InputWidget and TranslationTrait.
4754

48-
Version 1.5.0
49-
=============
55+
## Version 1.5.0
56+
5057
**Date:** 29-Nov-2014
5158

5259
- (enh #20): Enhance language locale file parsing and registering
@@ -55,16 +62,16 @@ Version 1.5.0
5562
- Utilize enhancements in krajee base [enh #9](https://github.com/kartik-v/yii2-krajee-base/issues/9) and [enh #10 ](https://github.com/kartik-v/yii2-krajee-base/issues/10)
5663
- Update `LanguageAsset` for new path
5764

58-
Version 1.4.0
59-
=============
65+
## Version 1.4.0
66+
6067
**Date:** 25-Nov-2014
6168

6269
- (enh #17): Updated Russian translations
6370
- (bug #18): Plugin data attributes not set because of input rendering sequence.
6471
- (enh #19): Enhance widget to use updated plugin registration from Krajee base
6572

66-
Version 1.3.0
67-
=============
73+
## Version 1.3.0
74+
6875
**Date:** 21-Nov-2014
6976

7077
- (enh #7): Added Russian Translations
@@ -74,23 +81,23 @@ Version 1.3.0
7481
- (enh #15): Revamp widget to remove dependency on custom locale JS files enhancement
7582
- (enh #16): Update Lithunian translations and create German translations.
7683

77-
Version 1.2.0
78-
=============
84+
## Version 1.2.0
85+
7986
**Date:** 20-Nov-2014
8087

8188
- (bug #11): Fix bug in daterangepicker.js for duplicate dates in Dec 2013.
8289
- Upgrade to latest plugin release 1.3.16 dated 12-Nov-2014.
8390

84-
Version 1.1.0
85-
=============
91+
## Version 1.1.0
92+
8693
**Date:** 10-Nov-2014
8794

8895
- PSR4 alias change
8996
- Set dependency on Krajee base components
9097
- Set release to stable
9198

92-
Version 1.0.0
93-
=============
99+
## Version 1.0.0
100+
94101
**Date:** 09-May-2014
95102

96103
- Initial release

DateRangePicker.php

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015
55
* @package yii2-date-range
6-
* @version 1.6.4
6+
* @version 1.6.5
77
*/
88

99
namespace kartik\daterange;
@@ -13,63 +13,69 @@
1313
use yii\helpers\Html;
1414
use yii\helpers\ArrayHelper;
1515
use yii\web\JsExpression;
16-
use yii\web\View;
16+
use kartik\base\InputWidget;
1717

1818
/**
19-
* An advanced date range picker input for Yii Framework 2 based on
20-
* bootstrap-daterangepicker plugin.
19+
* An advanced date range picker input for Yii Framework 2 based on bootstrap-daterangepicker plugin.
2120
*
2221
* @see https://github.com/dangrossman/bootstrap-daterangepicker
2322
* @author Kartik Visweswaran <[email protected]>
2423
* @since 1.0
2524
*/
26-
class DateRangePicker extends \kartik\base\InputWidget
25+
class DateRangePicker extends InputWidget
2726
{
2827
/**
29-
* @var string the javascript callback to be passed to the plugin constructor.
30-
* Note: a default value is set for this when you set `hideInput` to false, OR
31-
* you set `useWithAddon` to `true`.
28+
* @var string the javascript callback to be passed to the plugin constructor. Note: a default value is set for
29+
* this property when you set `hideInput` to false, OR you set `useWithAddon` to `true` or `autoUpdateOnInit` to
30+
* `false`. If you set a value here it will override any auto-generated callbacks.
3231
*/
33-
public $callback;
32+
public $callback = null;
33+
34+
/**
35+
* @var boolean whether to auto update the input on initialization. If set to `false`, this will auto set the
36+
* plugin's `autoUpdateInput` to `false`. A default `callback` will be auto-generated when this is set to `false`.
37+
*/
38+
public $autoUpdateOnInit = false;
39+
3440
/**
35-
* @var boolean whether to hide the input (e.g. when you want to show the date
36-
* range picker as a dropdown). If set to true, the input will be hidden. The plugin
37-
* will be initialized on a container element (default 'div'), using the container template.
38-
* A default `callback` will be setup in this case to display the selected range value within
39-
* the container.
41+
* @var boolean whether to hide the input (e.g. when you want to show the date range picker as a dropdown). If set
42+
* to `true`, the input will be hidden. The plugin will be initialized on a container element (default 'div'),
43+
* using the container template. A default `callback` will be setup in this case to display the selected range
44+
* value within the container.
4045
*/
4146
public $hideInput = false;
47+
4248
/**
43-
* @var boolean whether you are using the picker with a input group addon. You can set it
44-
* to `true`, when `hideInput` is false, and you wish to show the picker position more
45-
* correctly at the input-group-addon icon. A default `callback` will be setup in this case
46-
* to generate the selected range value for the input.
49+
* @var boolean whether you are using the picker with a input group addon. You can set it to `true`, when
50+
* `hideInput` is false, and you wish to show the picker position more correctly at the input-group-addon icon.
51+
* A default `callback` will be generated in this case to generate the selected range value for the input.
4752
*/
4853
public $useWithAddon = false;
54+
4955
/**
50-
* @var initialize all the list values set in `pluginOptions['ranges']`
51-
* and convert all values to yii\web\JsExpression
56+
* @var boolean initialize all the list values set in `pluginOptions['ranges']` and convert all values to
57+
* `yii\web\JsExpression`
5258
*/
5359
public $initRangeExpr = true;
60+
5461
/**
55-
* @var boolean show a preset dropdown. If set to true, this will automatically generate
56-
* a preset list of ranges for selection. Setting this to true will also automatically
57-
* set `initRangeExpr` to true.
62+
* @var boolean show a preset dropdown. If set to true, this will automatically generate a preset list of ranges
63+
* for selection. Setting this to true will also automatically set `initRangeExpr` to true.
5864
*/
5965
public $presetDropdown = false;
66+
6067
/**
61-
* @var array the HTML attributes for the container, if hideInput is set
62-
* to true. The following special options are recognized:
63-
* `tag`: string, the HTML tag for rendering the container. Defaults to `div`.
68+
* @var array the HTML attributes for the container, if hideInput is set to true. The following special options
69+
* are recognized:
70+
* - `tag`: string, the HTML tag for rendering the container. Defaults to `div`.
6471
*/
6572
public $containerOptions = ['class' => 'drp-container input-group'];
6673

6774
/**
68-
* @var array the template for rendering the container, when hideInput is set
69-
* to true. The special tag `{input}` will be replaced with the hidden form input.
70-
* In addition, the element with css class `range-value` will be replaced by the
71-
* calculated plugin value. The special tag `{value}` will be replaced with the
72-
* value of the hidden form input during initialization
75+
* @var array the template for rendering the container, when hideInput is set to `true`. The special tag `{input}`
76+
* will be replaced with the hidden form input. In addition, the element with css class `range-value` will be
77+
* replaced by the calculated plugin value. The special tag `{value}` will be replaced with the value of the hidden
78+
* form input during initialization
7379
*/
7480
public $containerTemplate = <<< HTML
7581
<span class="input-group-addon">
@@ -88,11 +94,12 @@ class DateRangePicker extends \kartik\base\InputWidget
8894
* @var array the HTML attributes for the form input
8995
*/
9096
public $options = ['class' => 'form-control'];
91-
97+
9298
/**
9399
* @inherit doc
94100
*/
95101
protected $_pluginName = 'daterangepicker';
102+
96103
/**
97104
* @var string locale language to be used for the plugin
98105
*/
@@ -101,12 +108,12 @@ class DateRangePicker extends \kartik\base\InputWidget
101108
/**
102109
* @var string the pluginOptions format for the date time
103110
*/
104-
private $_format;
111+
protected $_format;
105112

106113
/**
107114
* @var string the pluginOptions separator
108115
*/
109-
private $_separator;
116+
protected $_separator;
110117

111118
/**
112119
* Initializes the widget
@@ -135,6 +142,11 @@ public function init()
135142
$value = empty($this->value) ? '' : $this->value;
136143
$this->containerTemplate = str_replace('{value}', $value, $this->containerTemplate);
137144

145+
// Set `autoUpdateInput` to false for certain settings
146+
if (!$this->autoUpdateOnInit || $this->hideInput || $this->useWithAddon) {
147+
$this->pluginOptions['autoUpdateInput'] = false;
148+
}
149+
138150
$this->initRange();
139151
$this->containerOptions['id'] = $this->options['id'] . '-container';
140152
$this->registerAssets();
@@ -166,8 +178,8 @@ protected function initLocale()
166178
}
167179

168180
/**
169-
* Automatically convert the date format from PHP DateTime to Moment.js DateTime format
170-
* as required by bootstrap-daterangepicker plugin.
181+
* Automatically convert the date format from PHP DateTime to Moment.js DateTime format as required by
182+
* the `bootstrap-daterangepicker` plugin.
171183
*
172184
* @see http://php.net/manual/en/function.date.php
173185
* @see http://momentjs.com/docs/#/parsing/string-format/
@@ -230,6 +242,7 @@ protected static function convertDateFormat($format)
230242
protected function initRange()
231243
{
232244
if (isset($dummyValidation)) {
245+
/** @noinspection PhpUnusedLocalVariableInspection */
233246
$msg = Yii::t('kvdrp', 'Select Date Range');
234247
}
235248
if ($this->presetDropdown) {
@@ -297,32 +310,23 @@ public function registerAssets()
297310
}
298311
DateRangePickerAsset::register($view);
299312
if (empty($this->callback)) {
313+
$val = "start.format('{$this->_format}') + '{$this->_separator}' + end.format('{$this->_format}')";
314+
if (ArrayHelper::getValue($this->pluginOptions, 'singleDatePicker', false)) {
315+
$val = "start.format('{$this->_format}')";
316+
}
317+
$change = "{$input}.val(val);{$input}.trigger('change');";
300318
if ($this->hideInput) {
301-
$this->callback = <<< JS
302-
function(start, end) {
303-
var val = start.format('{$this->_format}') + '{$this->_separator}' + end.format('{$this->_format}');
304-
{$id}.find('.range-value').html(val);
305-
{$input}.val(val);
306-
{$input}.trigger('change');
307-
}
308-
JS;
319+
$script = "var val={$val};{$id}.find('.range-value').html(val);{$change}";
309320
} elseif ($this->useWithAddon) {
310321
$id = "{$input}.closest('.input-group')";
311-
$val = "start.format('{$this->_format}') + '{$this->_separator}' + end.format('{$this->_format}')";
312-
if (ArrayHelper::getValue($this->pluginOptions, 'singleDatePicker', false)) {
313-
$val = "start.format('{$this->_format}')";
314-
}
315-
$this->callback = <<< JS
316-
function(start, end) {
317-
var val = {$val};
318-
{$input}.val(val);
319-
{$input}.trigger('change');
320-
}
321-
JS;
322+
$script = "var val={$val};{$change}";
323+
} elseif (!$this->autoUpdateOnInit) {
324+
$script = "var val={$val};{$change}";
322325
} else {
323326
$this->registerPlugin($this->_pluginName, $id);
324327
return;
325328
}
329+
$this->callback = "function(start,end,label){{$script}}";
326330
}
327331
$this->registerPlugin($this->_pluginName, $id, null, $this->callback);
328332
}

DateRangePickerAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015
55
* @package yii2-date-range
6-
* @version 1.6.4
6+
* @version 1.6.5
77
*/
88

99
namespace kartik\daterange;

LanguageAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015
55
* @package yii2-date-range
6-
* @version 1.6.4
6+
* @version 1.6.5
77
*/
88

99
namespace kartik\daterange;

MomentAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015
55
* @package yii2-date-range
6-
* @version 1.6.4
6+
* @version 1.6.5
77
*/
88

99
namespace kartik\daterange;

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ yii2-date-range
22
=================
33

44
[![Latest Stable Version](https://img.shields.io/packagist/v/kartik-v/yii2-date-range.svg)](https://packagist.org/packages/kartik-v/yii2-date-range)
5-
[![License](https://img.shields.io/packagist/l/kartik-v/yii2-date-range.svg)](https://packagist.org/packages/kartik-v/yii2-date-range)
6-
[![Total Downloads](https://img.shields.io/packagist/dt/kartik-v/yii2-date-range.svg)](https://packagist.org/packages/kartik-v/yii2-date-range)
7-
[![Monthly Downloads](https://img.shields.io/packagist/dm/kartik-v/yii2-date-range.svg)](https://packagist.org/packages/kartik-v/yii2-date-range)
8-
[![Daily Downloads](https://img.shields.io/packagist/dd/kartik-v/yii2-date-range.svg)](https://packagist.org/packages/kartik-v/yii2-date-range)
5+
[![License](https://poser.pugx.org/kartik-v/yii2-date-range/license)](https://packagist.org/packages/kartik-v/yii2-date-range)
6+
[![Total Downloads](https://poser.pugx.org/kartik-v/yii2-date-range/downloads)](https://packagist.org/packages/kartik-v/yii2-date-range)
7+
[![Monthly Downloads](https://poser.pugx.org/kartik-v/yii2-date-range/d/monthly)](https://packagist.org/packages/kartik-v/yii2-date-range)
8+
[![Daily Downloads](https://poser.pugx.org/kartik-v/yii2-date-range/d/daily)](https://packagist.org/packages/kartik-v/yii2-date-range)
99

1010
An advanced date range picker input for Yii Framework 2 based on [dangrossman/bootstrap-daterangepicker plugin](https://github.com/dangrossman/bootstrap-daterangepicker).
1111
The date range picker widget is styled for Bootstrap 3.x and creates a dropdown menu from which a user can select a range of dates. If the plugin is invoked with no options,
@@ -27,7 +27,7 @@ Additional enhancements added for this widget (by Krajee):
2727
You can see detailed [documentation](http://demos.krajee.com/date-range) on usage of the extension.
2828

2929
### Latest Release
30-
The latest version of the extension is release v1.6.4. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-date-range/blob/master/CHANGE.md) for details of various releases.
30+
The latest version of the extension is release v1.6.5. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-date-range/blob/master/CHANGE.md) for details of various releases.
3131

3232
## Installation
3333

@@ -63,7 +63,9 @@ echo DateRangePicker::widget([
6363
'pluginOptions'=>[
6464
'timePicker'=>true,
6565
'timePickerIncrement'=>30,
66-
'locale'=>['format'=>'Y-m-d h:i A']
66+
'locale'=>[
67+
'format'=>'Y-m-d h:i A'
68+
]
6769
]
6870
]);
6971
```

0 commit comments

Comments
 (0)