DateRangeField
A widget to edit a start/end date pair. The two Dates are stored in the value property.
By default, the picker displays below the fields and edits the value "live":
//<code-header>
fiddle.title = 'Date range field';
//</code-header>
new DateRangeField({
appendTo : targetElement,
autoExpand : true,
rendition : 'outlined',
picker : {
align : 't-b50',
datePickerDefaults : {
shadePastDates : true
}
}
});
new DateRangeField({
appendTo : targetElement,
autoExpand : true,
rendition : 'filled',
picker : {
align : 't-b50',
datePickerDefaults : {
shadePastDates : true
}
},
fieldStartDate : {
placeholder : 'Departure'
},
fieldEndDate : {
placeholder : 'Return'
}
});//<code-header>
fiddle.title = 'Confirmable date range field';
//</code-header>
const firstDateOfMonth = DateHelper.getFirstDateOfMonth(new Date());
new DateRangeField({
appendTo : targetElement,
autoExpand : true,
// Adds a bottom toolbar with OK and Cancel buttons
confirmable : true,
rendition : 'outlined',
value : [DateHelper.add(firstDateOfMonth, 7, 'd'), DateHelper.add(firstDateOfMonth, 17, 'd')]
});
new DateRangeField({
appendTo : targetElement,
autoExpand : true,
// Adds a bottom toolbar with OK and Cancel buttons
confirmable : true,
rendition : 'filled',
value : [DateHelper.add(firstDateOfMonth, 7, 'd'), DateHelper.add(firstDateOfMonth, 17, 'd')]
});Cells in the month calendars presented in the picker can be customized with a cellRenderer:
//<code-header>
fiddle.title = 'Date range field cell renderer';
CSSHelper.insertRule([
'.date-range-field-demo .b-date-picker-cell-inner { padding:0.5em 0.75em 1em 0.75em; }',
'.date-range-field-demo .b-date-picker-cell-payload { margin-bottom:4px; }',
'.b-calendar-panel-cell:not(.b-active-date) .b-date-picker-cell-payload { opacity:0.65; }',
'.b-date-picker-cell-payload { font-size: 0.6em; white-space: nowrap; }',
'.therm { padding-inline-end : .5em;; }'
], targetElement.getRootNode());
//</code-header>
const picker = new DateRangeField({
appendTo : targetElement,
autoExpand : true,
value : ['today', 'today'],
picker : {
align : {
align : 't-b50'
},
cls : 'date-range-field-demo',
datePickerDefaults : {
shadePastDates : true
},
cellRenderer : ({ innerCell, cellPayload, date }) => {
const
CF = /US|LR|MM/i.test(new Intl.Locale(navigator.languages[0]).region) ? 'F' : 'C', // US/Liberia/Myanmar
convert = (CF === 'F') ? t => t : t => Math.floor((t - 32) * 5 / 9),
therm = v => Math.min(4, Math.max(0, Math.floor((v - 30) / 15))),
hiF = date % 31 + 47, // pseudo-random temperature
loF = hiF - date % 29 - 11,
hi = `${convert(hiF)} °${CF}`,
lo = `${convert(loF)} °${CF}`;
cellPayload.innerHTML = hi;
innerCell.dataset.btip =
`<div><span class="therm fa fa-thermometer-${therm(hiF)}"></span>High: ${hi}</div>` +
`<div><span class="therm fa fa-thermometer-${therm(loF)}"></span>Low: ${lo}</div>`;
}
},
listeners : {
change : ({ value }) => {
Toast.show(`You picked ${DateHelper.format(value[0], 'MMM DD')} to ${DateHelper.format(value[1], 'MMM DD')}`);
}
}
});Click on the calendars in the picker, or typing arrow keys will adjust the date range based on which of the individual date fields has the input focus.
Configs
123
Configs
123Other
Enables OK/Cancel button bar to accept date range changes. A value of true shows the OK and Cancel buttons.
See confirmable
A flag which indicates what time should be used for selected date.
false by default which means time is reset to midnight.
Possible options are:
falseto reset time to midnighttrueto keep original time value'17:00'a string which is parsed automaticallynew Date(2020, 0, 1, 17)a date object to copy time from'entered'to keep time value entered by user (in case format includes time info)
Max value
Min value
A config object used to configure the datePicker.
dateField = new DateRangeField({
picker : {
multiSelect : true
}
});
The week start day in the picker, 0 meaning Sunday, 6 meaning Saturday. Uses localized value per default.
DOM
Float & align
Input element
Label
Layout
Misc
Scrolling
Properties
95
Properties
95Class hierarchy
Other
Enables OK/Cancel button bar to accept date range changes. A value of true shows the OK and Cancel buttons.
See confirmable
Get/set max value, which can be a Date or a string. If a string is specified, it will be converted using the specified format.
Get/set min value, which can be a Date or a string. If a string is specified, it will be converted using the specified format.
CSS
DOM
Layout
Misc
Picker
Functions
67
Functions
67Configuration
Events
Misc
Other
Widget hierarchy
Events
19
Events
19Event handlers
19
Event handlers
19Typedefs
7
Typedefs
7CSS variables
125
CSS variables
125| Name | Description |
|---|---|
--b-date-range-field-gap | Gap between the start and end date fields |