File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 5
5
deserialize ,
6
6
isHTMLInputEvent ,
7
7
} from '../shared/internals'
8
- import { createForm } from '../'
8
+ import { createForm , onFieldValueChange } from '../'
9
9
import { attach } from './shared'
10
10
11
11
test ( 'getValuesFromEvent' , ( ) => {
@@ -109,3 +109,31 @@ test('isHTMLInputEvent', () => {
109
109
expect ( isHTMLInputEvent ( { target : { } , stopPropagation ( ) { } } ) ) . toBeFalsy ( )
110
110
expect ( isHTMLInputEvent ( { } ) ) . toBeFalsy ( )
111
111
} )
112
+
113
+ test ( 'reset when field display is none should be keep value' , ( ) => {
114
+ const valueChange = jest . fn ( )
115
+ const form = attach (
116
+ createForm ( {
117
+ initialValues : {
118
+ input : '123' ,
119
+ } ,
120
+ effects : ( ) => {
121
+ onFieldValueChange ( 'input' , valueChange )
122
+ } ,
123
+ } )
124
+ )
125
+ attach (
126
+ form . createField ( {
127
+ name : 'input' ,
128
+ } )
129
+ )
130
+ expect ( form . values . input ) . toEqual ( '123' )
131
+ form . fields [ 'input' ] . setDisplay ( 'none' )
132
+ expect ( form . values . input ) . toBeUndefined ( )
133
+ expect ( valueChange ) . toBeCalledTimes ( 1 )
134
+ form . reset ( )
135
+ form . reset ( )
136
+ form . fields [ 'input' ] . setDisplay ( 'visible' )
137
+ expect ( form . values . input ) . toEqual ( '123' )
138
+ expect ( valueChange ) . toBeCalledTimes ( 2 )
139
+ } )
Original file line number Diff line number Diff line change @@ -995,6 +995,13 @@ export const resetSelf = batch.bound(
995
995
target . inputValue = typedDefaultValue
996
996
target . inputValues = [ ]
997
997
target . caches = { }
998
+ if ( target . display === 'none' ) {
999
+ const value =
1000
+ options ?. forceClear || isUndef ( target . initialValue )
1001
+ ? typedDefaultValue
1002
+ : toJS ( target . initialValue )
1003
+ target . caches . value = value
1004
+ }
998
1005
if ( ! isUndef ( target . value ) ) {
999
1006
if ( options ?. forceClear ) {
1000
1007
target . value = typedDefaultValue
You can’t perform that action at this time.
0 commit comments