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 {
566
566
567
567
if ( onValuesChange ) {
568
568
const changedValues = cloneByNamePathList ( this . store , [ namePath ] ) ;
569
- onValuesChange ( changedValues , this . store ) ;
569
+ onValuesChange ( changedValues , this . getFieldsValue ( ) ) ;
570
570
}
571
571
572
572
this . triggerOnFieldsChange ( [ namePath , ...childrenFields ] ) ;
@@ -780,7 +780,7 @@ export class FormStore {
780
780
781
781
function useForm < Values = any > ( form ?: FormInstance < Values > ) : [ FormInstance < Values > ] {
782
782
const formRef = React . useRef < FormInstance > ( ) ;
783
- const [ , forceUpdate ] = React . useState ( ) ;
783
+ const [ , forceUpdate ] = React . useState ( { } ) ;
784
784
785
785
if ( ! formRef . current ) {
786
786
if ( form ) {
Original file line number Diff line number Diff line change @@ -212,6 +212,35 @@ describe('Form.Basic', () => {
212
212
expect ( onChange ) . toHaveBeenCalledWith ( expect . objectContaining ( { target : { value : 'Bamboo' } } ) ) ;
213
213
} ) ;
214
214
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
+
215
244
it ( 'submit' , async ( ) => {
216
245
const onFinish = jest . fn ( ) ;
217
246
const onFinishFailed = jest . fn ( ) ;
You can’t perform that action at this time.
0 commit comments