Skip to content

Commit 5996acc

Browse files
committed
feat(errorschema): errorSchema 支持直接配置在 uiSchema中
re #7
1 parent 2086c2c commit 5996acc

File tree

7 files changed

+29
-6
lines changed

7 files changed

+29
-6
lines changed

packages/docs/docs/zh/guide/basic-config.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ export default {
9898
* 类型:`object`
9999
* 默认值:`{}`
100100

101-
> `0.0.16` 之后版本支持配置 `uiSchema``schema` 参数中 [点击查看](#uischema配置在schema中)
101+
>* `0.0.16` 之后版本支持配置 `uiSchema``schema` 参数中 [点击查看](#uischema配置在schema中)
102+
>* `0.0.17` 之后版本支持配置 [errorSchema](#errorschema)[uiSchema](#uischema) 中。(`uiSchema``errorSchema` 格式完全相同,且同属ui显示,一份可方便配置)
102103
103104
用于配置表单展示样式,普通json数据,非 `JSON Schema` 规范
104105

@@ -254,7 +255,8 @@ export default {
254255
'ui:emptyValue': '',
255256
'ui:options': {
256257
attrs: {
257-
'autofocus': true
258+
autofocus: true,
259+
rows: 6,
258260
},
259261
style: {
260262
boxShadow: '0 0 6px 2px #2b9939'
@@ -263,7 +265,6 @@ export default {
263265
className_hei: true
264266
},
265267
type: 'textarea',
266-
rows: '6',
267268
placeholder: '请输入你的内容'
268269
}
269270
},
@@ -284,7 +285,7 @@ export default {
284285
::: warning 注意
285286
配置数据结构是和 `schema` 保持一致,而非 `formData` 一致
286287

287-
比如
288+
比如配置数组元素
288289
```js
289290

290291
// schema
@@ -341,7 +342,8 @@ uiSchema = {
341342
* 类型:`object`
342343
* 默认值:`{}`
343344

344-
> `0.0.16` 之后版本支持配置 `errorSchema``schema` 参数中 [点击查看](#errorschema配置在schema中)
345+
>* `0.0.16` 之后版本支持配置 `errorSchema``schema` 参数中 [点击查看](#errorschema配置在schema中)
346+
>* `0.0.17` 之后版本支持配置 [errorSchema](#errorschema)[uiSchema](#uischema) 中。(`uiSchema``errorSchema` 格式完全相同,且同属ui显示,一份可方便配置)
345347
346348
用于配置表单校验错误文案信息,普通json数据,非JSON Schema规范
347349

@@ -370,6 +372,7 @@ errorSchema配置演示:重置表单错误信息
370372
<vue-form
371373
v-model="formData"
372374
:schema="schema"
375+
:uiSchema="uiSchema"
373376
:error-schema="errorSchema"
374377
>
375378
</vue-form>
@@ -430,6 +433,13 @@ export default {
430433
}
431434
}
432435
},
436+
uiSchema: {
437+
bio: {
438+
'ui:type': 'textarea',
439+
'ui:placeholder': '请输入 ...',
440+
'err:required': '请输入(uiSchema中配置)',
441+
},
442+
},
433443
errorSchema: {
434444
userName: {
435445
'err:options': {

packages/lib/src/JsonSchemaForm/common/formUtils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ export function getWidgetConfig({
186186
// 解析用户配置的 errorSchema options
187187
export function getUserErrOptions({
188188
schema = {},
189+
uiSchema = {},
189190
errorSchema = {}
190191
}) {
191-
return Object.assign({}, ...[schema, errorSchema].map(itemSchema => Object.keys(itemSchema)
192+
return Object.assign({}, ...[schema, uiSchema, errorSchema].map(itemSchema => Object.keys(itemSchema)
192193
.filter(key => key.indexOf('err:') === 0)
193194
.reduce((options, key) => {
194195
const value = itemSchema[key];

packages/lib/src/JsonSchemaForm/common/schema/validate.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export function ajvValidateFormData({
150150
export function validateFormDataAndTransformMsg({
151151
formData,
152152
schema,
153+
uiSchema,
153154
transformErrors,
154155
additionalMetaSchemas = [],
155156
customFormats = {},
@@ -177,6 +178,7 @@ export function validateFormDataAndTransformMsg({
177178
// 用户设置校验信息
178179
const errSchemaMsg = getUserErrOptions({
179180
schema,
181+
uiSchema,
180182
errorSchema
181183
}).required;
182184
if (errSchemaMsg) {
@@ -212,6 +214,7 @@ export function validateFormDataAndTransformMsg({
212214

213215
const userErrOptions = getUserErrOptions({
214216
schema,
217+
uiSchema,
215218
errorSchema
216219
});
217220

packages/lib/src/JsonSchemaForm/fieldComponents/Widget.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export default {
2626
type: Object,
2727
default: () => ({})
2828
},
29+
uiSchema: {
30+
type: Object,
31+
default: () => ({})
32+
},
2933
errorSchema: {
3034
type: Object,
3135
default: () => ({})
@@ -155,6 +159,7 @@ export default {
155159
const errors = validateFormDataAndTransformMsg({
156160
formData: value,
157161
schema: self.$props.schema,
162+
uiSchema: self.$props.uiSchema,
158163
customFormats: self.$props.customFormats,
159164
errorSchema: self.errorSchema,
160165
required: self.required,

packages/lib/src/JsonSchemaForm/fields/ArrayField/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export default {
208208
if (key !== 'items') preVal[key] = value;
209209
return preVal;
210210
}, {}),
211+
uiSchema,
211212
errorSchema: this.errorSchema,
212213
curNodePath,
213214
rootFormData

packages/lib/src/JsonSchemaForm/fields/ObjectField/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export default {
9696
) preVal[key] = value;
9797
return preVal;
9898
}, {}),
99+
uiSchema,
99100
errorSchema,
100101
curNodePath: props.curNodePath,
101102
rootFormData: props.rootFormData

packages/lib/src/JsonSchemaForm/fields/combiningSchemas/SelectLinkageField/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export default {
171171

172172
const userErrOptions = filterObject(getUserErrOptions({
173173
schema: this.schema,
174+
uiSchema: this.uiSchema,
174175
errorSchema: this.errorSchema
175176
}), key => (key === this.combiningType ? undefined : `err:${key}`));
176177

@@ -208,6 +209,7 @@ export default {
208209
},
209210
props: {
210211
schema: this.schema,
212+
uiSchema: this.uiSchema,
211213
errorSchema: this.errorSchema,
212214
curNodePath: this.curNodePath,
213215
rootFormData: this.rootFormData,

0 commit comments

Comments
 (0)