choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
45 lines (40 loc) • 1.73 kB
JavaScript
import { isArrayLike } from 'mobx';
import isEmpty from '../../_util/isEmpty';
import ValidationResult from '../ValidationResult';
import { $l } from '../../locale-context';
import { formatReactTemplate } from '../../formatter/formatReactTemplate';
import { FieldType } from '../../data-set/enum';
import { toRangeValue } from '../../field/utils';
function isEmptyArray(value) {
return isEmpty(value) || isArrayLike(value) && (value.length === 0 || value.every(function (item) {
return isEmptyArray(item);
}));
}
export default function valueMissing(value, props) {
var required = props.required,
label = props.label,
multiple = props.multiple,
range = props.range,
defaultValidationMessages = props.defaultValidationMessages,
type = props.type,
attachmentCount = props.attachmentCount;
if (required && (isEmptyArray(value) || type === FieldType.attachment && !attachmentCount || range && (multiple ? value.every(function (item) {
return isEmptyArray(toRangeValue(item, range));
}) : isEmptyArray(toRangeValue(value, range))))) {
var injectionOptions = {
label: label
};
var key = label ? 'value_missing' : 'value_missing_no_label';
var ruleName = label ? 'valueMissing' : 'valueMissingNoLabel';
var _defaultValidationMes = defaultValidationMessages[ruleName],
validationMessage = _defaultValidationMes === void 0 ? $l('Validator', key) : _defaultValidationMes;
return new ValidationResult({
validationMessage: formatReactTemplate(validationMessage, injectionOptions),
injectionOptions: injectionOptions,
value: value,
ruleName: ruleName
});
}
return true;
}
//# sourceMappingURL=valueMissing.js.map