From 6ff27bc335e10923d3708590d80168faa8e84f08 Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Tue, 19 Nov 2019 19:47:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20formitem=20=E7=9A=84?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=94=E8=AF=A5=E8=AE=B0=E5=BD=95=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E4=B8=80=E6=AC=A1=E7=9A=84=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/Form/Control.tsx | 17 +++++++---------- src/store/formItem.ts | 10 +++++++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/renderers/Form/Control.tsx b/src/renderers/Form/Control.tsx index 74542149c..e615f3fb7 100644 --- a/src/renderers/Form/Control.tsx +++ b/src/renderers/Form/Control.tsx @@ -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) { diff --git a/src/store/formItem.ts b/src/store/formItem.ts index e4c45b1ae..3b555d3a3 100644 --- a/src/store/formItem.ts +++ b/src/store/formItem.ts @@ -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); } }