Et2DateTime: Limit minutes to multiples of 5

This commit is contained in:
nathan 2022-10-14 11:18:17 -06:00
parent b0fc18ad93
commit c52ac8fbdc
2 changed files with 29 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import 'lit-flatpickr';
import {Et2InputWidget} from "../Et2InputWidget/Et2InputWidget";
import {dateStyles} from "./DateStyles";
import {LitFlatpickr} from "lit-flatpickr";
import {Instance} from 'flatpickr/dist/types/instance';
import "flatpickr/dist/plugins/scrollPlugin.js";
import "shortcut-buttons-flatpickr/dist/shortcut-buttons-flatpickr";
import {holidays} from "./Holidays";
@ -589,7 +590,7 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(ValidateMixin(LitFl
* @param _ev
* @returns
*/
_updateValueOnChange(_ev : Event)
_updateValueOnChange(selectedDates : Date[], dateStr : string, instance : Instance)
{
this.modelValue = this.getValue();
}

View File

@ -11,6 +11,7 @@
import {css} from "@lion/core";
import {Et2Date} from "./Et2Date";
import {Instance} from "flatpickr/dist/types/instance";
export class Et2DateTime extends Et2Date
@ -67,6 +68,32 @@ export class Et2DateTime extends Et2Date
return options;
}
/**
* Change handler setting modelValue for validation
*
* @returns
* @param selectedDates
* @param dateStr
* @param instance
*/
_updateValueOnChange(selectedDates : Date[], dateStr : string, instance : Instance)
{
super._updateValueOnChange(selectedDates, dateStr, instance);
if(this._instance && instance.config.minuteIncrement > 1)
{
let i = instance.latestSelectedDateObj;
const d = i ? i : new Date();
const original = d.getMinutes();
let bound = Math.round(original / instance.config.minuteIncrement) * instance.config.minuteIncrement;
if(bound != original)
{
d.setMinutes(bound);
instance.setDate(d, false);
}
}
}
/**
* Add "today" button below calendar
* @protected