File tree Expand file tree Collapse file tree 2 files changed +32
-13
lines changed Expand file tree Collapse file tree 2 files changed +32
-13
lines changed Original file line number Diff line number Diff line change @@ -2298,12 +2298,39 @@ test('field actions', () => {
2298
2298
2299
2299
test ( 'field hidden value' , ( ) => {
2300
2300
const form = attach ( createForm ( ) )
2301
- attach (
2301
+ const aa = attach (
2302
2302
form . createField ( {
2303
2303
name : 'aa' ,
2304
2304
hidden : true ,
2305
2305
initialValue : '123' ,
2306
2306
} )
2307
2307
)
2308
2308
expect ( form . values ) . toEqual ( { aa : '123' } )
2309
+
2310
+ const objectField = attach (
2311
+ form . createObjectField ( {
2312
+ name : 'object' ,
2313
+ hidden : true ,
2314
+ } )
2315
+ )
2316
+ const arrayField = attach (
2317
+ form . createArrayField ( {
2318
+ name : 'array' ,
2319
+ hidden : true ,
2320
+ } )
2321
+ )
2322
+
2323
+ aa . setDisplay ( 'none' )
2324
+ objectField . setDisplay ( 'none' )
2325
+ arrayField . setDisplay ( 'none' )
2326
+ expect ( aa . value ) . toBeUndefined ( )
2327
+ expect ( objectField . value ) . toBeUndefined ( )
2328
+ expect ( arrayField . value ) . toBeUndefined ( )
2329
+
2330
+ aa . setDisplay ( 'hidden' )
2331
+ objectField . setDisplay ( 'hidden' )
2332
+ arrayField . setDisplay ( 'hidden' )
2333
+ expect ( aa . value ) . toEqual ( '123' )
2334
+ expect ( objectField . value ) . toEqual ( { } )
2335
+ expect ( arrayField . value ) . toEqual ( [ ] )
2309
2336
} )
Original file line number Diff line number Diff line change 1
- import {
2
- isValid ,
3
- isEmpty ,
4
- toArr ,
5
- FormPathPattern ,
6
- isArr ,
7
- } from '@formily/shared'
1
+ import { isValid , toArr , FormPathPattern , isArr } from '@formily/shared'
8
2
import {
9
3
ValidatorTriggerType ,
10
4
parseValidatorDescriptions ,
@@ -245,16 +239,14 @@ export class Field<
245
239
( ) => this . display ,
246
240
( display ) => {
247
241
const value = this . value
248
- if ( display === 'visible ') {
249
- if ( isEmpty ( value ) ) {
242
+ if ( display !== 'none ') {
243
+ if ( ! isValid ( value ) ) {
250
244
this . setValue ( this . caches . value )
251
245
this . caches . value = undefined
252
246
}
253
247
} else {
254
248
this . caches . value = toJS ( value ) ?? toJS ( this . initialValue )
255
- if ( display === 'none' ) {
256
- this . form . deleteValuesIn ( this . path )
257
- }
249
+ this . form . deleteValuesIn ( this . path )
258
250
}
259
251
if ( display === 'none' || display === 'hidden' ) {
260
252
this . setFeedback ( {
You can’t perform that action at this time.
0 commit comments