UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

45 lines (39 loc) 1.49 kB
import { isMoment } from 'moment'; import isNil from 'lodash/isNil'; import isEmpty from '../../_util/isEmpty'; import ValidationResult from '../ValidationResult'; import { $l } from '../../locale-context'; import { formatReactTemplate } from '../../formatter/formatReactTemplate'; import { toRangeValue } from '../../field/utils'; var isOverflow = function isOverflow(value, max, range) { if (range) { return toRangeValue(value, range).some(function (item) { return !isEmpty(item) && Number(item) > Number(max); }); } return !isEmpty(value) && Number(value) > Number(max); }; export default function rangeOverflow(value, props) { var max = props.max, label = props.label, format = props.format, defaultValidationMessages = props.defaultValidationMessages, range = props.range; if (!isNil(max) && isOverflow(value, max, range)) { var injectionOptions = { max: isMoment(max) ? max.format(format) : max, label: label }; var ruleName = 'rangeOverflow'; var _defaultValidationMes = defaultValidationMessages[ruleName], validationMessage = _defaultValidationMes === void 0 ? $l('Validator', 'range_overflow') : _defaultValidationMes; return new ValidationResult({ validationMessage: formatReactTemplate(validationMessage, injectionOptions), injectionOptions: injectionOptions, value: value, ruleName: ruleName }); } return true; } //# sourceMappingURL=rangeOverflow.js.map