Commit c177430 1 parent 9df3eee commit c177430 Copy full SHA for c177430
File tree 3 files changed +61
-2
lines changed
packages/react-schema-renderer/src
3 files changed +61
-2
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,24 @@ describe('major scene', () => {
140
140
} ,
141
141
p5 : {
142
142
'x-index' : 5
143
+ } ,
144
+ p6 : {
145
+ 'x-index' : 6
146
+ } ,
147
+ p7 : {
148
+ 'x-index' : 7
149
+ } ,
150
+ p8 : {
151
+ 'x-index' : 8
152
+ } ,
153
+ p9 : {
154
+ 'x-index' : 9
155
+ } ,
156
+ p10 : {
157
+ 'x-index' : 10
158
+ } ,
159
+ p11 : {
160
+ 'x-index' : 11
143
161
}
144
162
}
145
163
} )
@@ -149,7 +167,13 @@ describe('major scene', () => {
149
167
'p3' ,
150
168
'p2' ,
151
169
'p4' ,
152
- 'p5'
170
+ 'p5' ,
171
+ 'p6' ,
172
+ 'p7' ,
173
+ 'p8' ,
174
+ 'p9' ,
175
+ 'p10' ,
176
+ 'p11' ,
153
177
] )
154
178
155
179
// 多排序
Original file line number Diff line number Diff line change @@ -117,6 +117,39 @@ test('basic validate', async () => {
117
117
expect ( getByText ( 'This field is required' ) ) . toBeVisible ( )
118
118
} )
119
119
120
+ test ( 'object validate' , async ( ) => {
121
+ const handleSubmit = jest . fn ( )
122
+ const handleValidateFailed = jest . fn ( )
123
+ const TestComponent = ( ) => (
124
+ < SchemaForm onSubmit = { handleSubmit } onValidateFailed = { handleValidateFailed } >
125
+ < Fragment >
126
+ < Field
127
+ type = "object"
128
+ name = "user"
129
+ required = { [ 'username' , 'age' ] }
130
+ >
131
+ < Field type = "string" name = "username" title = "username" />
132
+ < Field type = "string" name = "age" title = "age" />
133
+ </ Field >
134
+ < button type = "submit" data-testid = "btn" >
135
+ Submit
136
+ </ button >
137
+ </ Fragment >
138
+ </ SchemaForm >
139
+ )
140
+
141
+ const { getByTestId, findAllByText } = render ( < TestComponent /> )
142
+
143
+ fireEvent . click ( getByTestId ( 'btn' ) )
144
+ await wait ( )
145
+ fireEvent . click ( getByTestId ( 'btn' ) )
146
+ await wait ( )
147
+ expect ( handleSubmit ) . toHaveBeenCalledTimes ( 0 )
148
+ expect ( handleValidateFailed ) . toHaveBeenCalledTimes ( 2 )
149
+ const errTexts = await findAllByText ( 'This field is required' )
150
+ expect ( errTexts ) . toHaveLength ( 2 )
151
+ } )
152
+
120
153
test ( 'validate in init' , async ( ) => {
121
154
const handleSubmit = jest . fn ( )
122
155
const handleValidateFailed = jest . fn ( )
Original file line number Diff line number Diff line change @@ -310,6 +310,8 @@ export class Schema implements ISchema {
310
310
getExtendsRequired ( ) {
311
311
if ( isBool ( this . required ) ) {
312
312
return this . required
313
+ } else if ( isArr ( this . parent ?. required ) && this . parent ?. required . includes ( this . key ) ) {
314
+ return true
313
315
}
314
316
}
315
317
getExtendsEditable ( ) : boolean {
@@ -512,7 +514,7 @@ export class Schema implements ISchema {
512
514
const unorderProperties = [ ]
513
515
each ( newSchema [ propertiesName ] , ( item , key ) => {
514
516
const index = item [ 'x-index' ]
515
- if ( typeof index === 'number' ) {
517
+ if ( ! isNaN ( index ) ) {
516
518
orderProperties [ index ] = { schema : item , key }
517
519
} else {
518
520
unorderProperties . push ( { schema : item , key } )
You can’t perform that action at this time.
0 commit comments