mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Datepicker: allow specify display format (#1919)
* Apply datepicker `format` property reading from config. * Using the format property on partial.
This commit is contained in:
parent
c351ff8411
commit
6a897b1072
@ -19,6 +19,11 @@ class DatePicker extends FormWidgetBase
|
||||
// Configurable properties
|
||||
//
|
||||
|
||||
/**
|
||||
* @var string Display format.
|
||||
*/
|
||||
public $format = 'YYYY-MM-DD';
|
||||
|
||||
/**
|
||||
* @var bool Display mode: datetime, date, time.
|
||||
*/
|
||||
@ -49,6 +54,7 @@ class DatePicker extends FormWidgetBase
|
||||
public function init()
|
||||
{
|
||||
$this->fillFromConfig([
|
||||
'format',
|
||||
'mode',
|
||||
'minDate',
|
||||
'maxDate',
|
||||
@ -119,6 +125,7 @@ class DatePicker extends FormWidgetBase
|
||||
|
||||
$this->vars['value'] = $value ?: '';
|
||||
$this->vars['field'] = $this->formField;
|
||||
$this->vars['format'] = $this->format;
|
||||
$this->vars['mode'] = $this->mode;
|
||||
$this->vars['minDate'] = $this->minDate;
|
||||
$this->vars['maxDate'] = $this->maxDate;
|
||||
|
@ -1,8 +1,9 @@
|
||||
/*
|
||||
* DatePicker plugin
|
||||
*
|
||||
*
|
||||
* Data attributes:
|
||||
* - data-control="datepicker" - enables the plugin on an element
|
||||
* - data-format="value" - display format
|
||||
* - data-min-date="value" - minimum date to allow
|
||||
* - data-max-date="value" - maximum date to allow
|
||||
* - data-year-range="value" - range of years to display
|
||||
@ -38,6 +39,7 @@
|
||||
minDate: new Date(options.minDate),
|
||||
maxDate: new Date(options.maxDate),
|
||||
yearRange: options.yearRange,
|
||||
format: options.format,
|
||||
setDefaultDate: moment(this.$input.val()).toDate(),
|
||||
i18n: $.oc.lang.get('datepicker'),
|
||||
onOpen: function() {
|
||||
@ -57,6 +59,7 @@
|
||||
DatePicker.DEFAULTS = {
|
||||
minDate: '2000-01-01',
|
||||
maxDate: '2020-12-31',
|
||||
format: 'YYYY-MM-DD',
|
||||
yearRange: 10
|
||||
}
|
||||
|
||||
@ -93,4 +96,4 @@
|
||||
$('[data-control="datepicker"]').datePicker()
|
||||
});
|
||||
|
||||
}(window.jQuery);
|
||||
}(window.jQuery);
|
||||
|
@ -8,6 +8,7 @@
|
||||
id="<?= $this->getId() ?>"
|
||||
class="field-datepicker"
|
||||
data-control="datepicker"
|
||||
data-format="<?= $format ?>"
|
||||
data-min-date="<?= $minDate ?>"
|
||||
data-max-date="<?= $maxDate ?>">
|
||||
<div class="input-with-icon right-align">
|
||||
@ -32,6 +33,7 @@
|
||||
id="<?= $this->getId() ?>"
|
||||
class="field-datepicker"
|
||||
data-control="datepicker"
|
||||
data-format="<?= $format ?>"
|
||||
data-min-date="<?= $minDate ?>"
|
||||
data-max-date="<?= $maxDate ?>">
|
||||
<div class="input-with-icon right-align">
|
||||
@ -95,4 +97,4 @@
|
||||
|
||||
<?php endif ?>
|
||||
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user