修改Options的验证方式

This commit is contained in:
catchonme 2019-08-21 11:17:47 +08:00
parent 891a935f65
commit 7d5401c237
5 changed files with 9 additions and 9 deletions

View File

@ -331,7 +331,6 @@ export class TreeSelector extends React.Component<TreeSelectorProps, TreeSelecto
let nodeDisabled = !!uncheckable || !!disabled || selfDisabled;
// todo 加验证,提交前需要验证不能超出 maxLength 或者少于 minLength
if (
!nodeDisabled
&& (

View File

@ -158,10 +158,6 @@ export function registerOptionsControl(config: OptionsConfig) {
return false;
}
validate() {
return Control.prototype.validate && Control.prototype.validate.call(this);
}
componentWillReceiveProps(nextProps:OptionsControlProps) {
const props = this.props;
const formItem = nextProps.formItem as IFormItemStore;
@ -230,6 +226,10 @@ export function registerOptionsControl(config: OptionsConfig) {
}
}
getWrappedInstance() {
return this.input;
}
inputRef(ref:any) {
this.input = ref;
}

View File

@ -89,6 +89,7 @@ export interface FormProps extends RendererProps, FormSchema {
canAccessSuperData: boolean;
persistData: boolean; // 开启本地缓存
clearPersistDataAfterSubmit: boolean; // 提交成功后清空本地缓存
trimValues?: boolean;
onInit?: (values:object) => any;
onReset?: (values:object) => void;
onSubmit?: (values:object, action:any) => any;
@ -487,10 +488,10 @@ export default class Form extends React.Component<FormProps, object> {
env,
onChange,
clearPersistDataAfterSubmit,
trim
trimValues
} = this.props;
if (trim) {
if (trimValues) {
store.trimValues();
}

View File

@ -493,7 +493,7 @@ export const FormItemStore = types
}
function trimValue() {
let value = iterateChildren(self.value, (item:any) => typeof item === 'string' && item.trim());
let value = iterateChildren(self.value, (item:any) => typeof item === 'string' ? item.trim() : item);
value && changeValue(value, false);
}

View File

@ -731,7 +731,7 @@ export function iterateChildren(value: any, fn: Function): any {
return value.map(item => iterateChildren(item, fn));
}
if (isObject(value)) {
let tmpValue = Object.assign({}, value);
let tmpValue = {...value};
Object.keys(tmpValue).forEach(key => {
(tmpValue as PlainObject)[key] = iterateChildren((tmpValue as PlainObject)[key], fn);
});