修复 formitem 的修改应该记录最后一次的结果

This commit is contained in:
liaoxuezhi 2019-11-19 19:47:02 +08:00
parent 47008ca307
commit 6ff27bc335
2 changed files with 14 additions and 13 deletions

View File

@ -53,7 +53,7 @@ export default class FormControl extends React.PureComponent<
static defaultProps = {};
lazyValidate: Function;
lazyEmitChange: (value: any, submitOnChange: boolean) => void;
lazyEmitChange: (submitOnChange: boolean) => void;
state = {value: this.props.control.value};
componentWillMount() {
const {
@ -142,7 +142,7 @@ export default class FormControl extends React.PureComponent<
if (name && form !== store) {
const value = getVariable(store.data, name);
if (typeof value !== 'undefined' && value !== this.getValue()) {
this.emitChange(value, false);
this.handleChange(value, false, true);
}
}
@ -261,7 +261,7 @@ export default class FormControl extends React.PureComponent<
(value = getVariable(data as any, name)) !==
getVariable(prevProps.data, name)
) {
this.emitChange(value, false);
this.handleChange(value, false, true);
}
}
@ -362,15 +362,12 @@ export default class FormControl extends React.PureComponent<
},
() =>
changeImmediately
? this.emitChange(value, submitOnChange)
: this.lazyEmitChange(value, submitOnChange)
? this.emitChange(submitOnChange)
: this.lazyEmitChange(submitOnChange)
);
}
emitChange(
value: any,
submitOnChange: boolean = this.props.control.submitOnChange
) {
emitChange(submitOnChange: boolean = this.props.control.submitOnChange) {
const {
formStore: form,
onChange,
@ -379,7 +376,7 @@ export default class FormControl extends React.PureComponent<
if (!this.model) {
return;
}
let value = this.state.value;
const oldValue = this.model.value;
if (pipeOut) {

View File

@ -342,7 +342,11 @@ export const FormItemStore = types
data: object,
options?: fetchOptions,
clearValue?: any,
onChange?: (value: any) => void
onChange?: (
value: any,
submitOnChange: boolean,
changeImmediately: boolean
) => void
) {
try {
if (loadCancel) {
@ -387,11 +391,11 @@ export const FormItemStore = types
setOptions(options);
if (json.data && typeof (json.data as any).value !== 'undefined') {
onChange && onChange((json.data as any).value);
onChange && onChange((json.data as any).value, false, true);
} else if (clearValue) {
self.selectedOptions.some((item: any) => item.__unmatched) &&
onChange &&
onChange('');
onChange('', false, true);
}
}