Skip to content

Commit c177430

Browse files
fix: issue 853 and 860 (#928)
fix issue
1 parent 9df3eee commit c177430

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

packages/react-schema-renderer/src/__tests__/schema.spec.tsx

+25-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ describe('major scene', () => {
140140
},
141141
p5: {
142142
'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
143161
}
144162
}
145163
})
@@ -149,7 +167,13 @@ describe('major scene', () => {
149167
'p3',
150168
'p2',
151169
'p4',
152-
'p5'
170+
'p5',
171+
'p6',
172+
'p7',
173+
'p8',
174+
'p9',
175+
'p10',
176+
'p11',
153177
])
154178

155179
// 多排序

packages/react-schema-renderer/src/__tests__/validate.spec.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,39 @@ test('basic validate', async () => {
117117
expect(getByText('This field is required')).toBeVisible()
118118
})
119119

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+
120153
test('validate in init', async () => {
121154
const handleSubmit = jest.fn()
122155
const handleValidateFailed = jest.fn()

packages/react-schema-renderer/src/shared/schema.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ export class Schema implements ISchema {
310310
getExtendsRequired() {
311311
if (isBool(this.required)) {
312312
return this.required
313+
} else if (isArr(this.parent?.required) && this.parent?.required.includes(this.key)) {
314+
return true
313315
}
314316
}
315317
getExtendsEditable(): boolean {
@@ -512,7 +514,7 @@ export class Schema implements ISchema {
512514
const unorderProperties = []
513515
each(newSchema[propertiesName], (item, key) => {
514516
const index = item['x-index']
515-
if (typeof index === 'number') {
517+
if (!isNaN(index)) {
516518
orderProperties[index] = { schema: item, key }
517519
} else {
518520
unorderProperties.push({ schema: item, key })

0 commit comments

Comments
 (0)