File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -566,7 +566,7 @@ export class FormStore {
566566
567567 if ( onValuesChange ) {
568568 const changedValues = cloneByNamePathList ( this . store , [ namePath ] ) ;
569- onValuesChange ( changedValues , this . store ) ;
569+ onValuesChange ( changedValues , this . getFieldsValue ( ) ) ;
570570 }
571571
572572 this . triggerOnFieldsChange ( [ namePath , ...childrenFields ] ) ;
@@ -780,7 +780,7 @@ export class FormStore {
780780
781781function useForm < Values = any > ( form ?: FormInstance < Values > ) : [ FormInstance < Values > ] {
782782 const formRef = React . useRef < FormInstance > ( ) ;
783- const [ , forceUpdate ] = React . useState ( ) ;
783+ const [ , forceUpdate ] = React . useState ( { } ) ;
784784
785785 if ( ! formRef . current ) {
786786 if ( form ) {
Original file line number Diff line number Diff line change @@ -212,6 +212,35 @@ describe('Form.Basic', () => {
212212 expect ( onChange ) . toHaveBeenCalledWith ( expect . objectContaining ( { target : { value : 'Bamboo' } } ) ) ;
213213 } ) ;
214214
215+ it ( 'onValuesChange should not return fully value' , async ( ) => {
216+ const onValuesChange = jest . fn ( ) ;
217+
218+ const Demo = ( { showField = true } ) => (
219+ < Form onValuesChange = { onValuesChange } initialValues = { { light : 'little' } } >
220+ { showField && (
221+ < Field name = "light" >
222+ < Input />
223+ </ Field >
224+ ) }
225+ < Field name = "bamboo" >
226+ < Input />
227+ </ Field >
228+ </ Form >
229+ ) ;
230+
231+ const wrapper = mount ( < Demo /> ) ;
232+ await changeValue ( getField ( wrapper , 'bamboo' ) , 'cute' ) ;
233+ expect ( onValuesChange ) . toHaveBeenCalledWith ( expect . anything ( ) , {
234+ light : 'little' ,
235+ bamboo : 'cute' ,
236+ } ) ;
237+
238+ onValuesChange . mockReset ( ) ;
239+ wrapper . setProps ( { showField : false } ) ;
240+ await changeValue ( getField ( wrapper , 'bamboo' ) , 'beauty' ) ;
241+ expect ( onValuesChange ) . toHaveBeenCalledWith ( expect . anything ( ) , { bamboo : 'beauty' } ) ;
242+ } ) ;
243+
215244 it ( 'submit' , async ( ) => {
216245 const onFinish = jest . fn ( ) ;
217246 const onFinishFailed = jest . fn ( ) ;
You can’t perform that action at this time.
0 commit comments