UNPKG

igniteui-webcomponents

Version:

Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.

57 lines 2.16 kB
import { calendarRange, isDateInRanges } from '../calendar/helpers.js'; import { CalendarDay } from '../calendar/model.js'; import messages from '../common/localization/validation-en.js'; import { formatString, isEmpty } from '../common/util.js'; export const minDateRangeValidator = { key: 'rangeUnderflow', message: ({ min }) => formatString(messages.min, min), isValid: ({ value, min }) => { if (!min) { return true; } const isStartInvalid = value?.start && CalendarDay.compare(value.start, min) < 0; const isEndInvalid = value?.end && CalendarDay.compare(value.end, min) < 0; return !(isStartInvalid || isEndInvalid); }, }; export const maxDateRangeValidator = { key: 'rangeOverflow', message: ({ max }) => formatString(messages.max, max), isValid: ({ value, max }) => { if (!max) { return true; } const isStartInvalid = value?.start && CalendarDay.compare(value.start, max) > 0; const isEndInvalid = value?.end && CalendarDay.compare(value.end, max) > 0; return !(isStartInvalid || isEndInvalid); }, }; export const requiredDateRangeValidator = { key: 'valueMissing', message: messages.required, isValid: ({ required, value }) => { return required ? isCompleteDateRange(value) : true; }, }; export const badInputDateRangeValidator = { key: 'badInput', message: ({ value }) => formatString(messages.disabledDate, value), isValid: ({ value, disabledDates }) => { if (!isCompleteDateRange(value) || !disabledDates || isEmpty(disabledDates)) { return true; } return Array.from(calendarRange({ start: value.start, end: value.end, inclusive: true })).every((date) => !isDateInRanges(date, disabledDates)); }, }; export const dateRangeValidators = [ requiredDateRangeValidator, minDateRangeValidator, maxDateRangeValidator, badInputDateRangeValidator, ]; export function isCompleteDateRange(value) { return value != null && value.start != null && value.end != null; } //# sourceMappingURL=validators.js.map