mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-01-24 04:10:20 +08:00
feat(from): add required in schema
This commit is contained in:
parent
b6d5e5c96f
commit
2859067621
@ -102,13 +102,19 @@ export default defineComponent({
|
||||
rulesMessageJoinLabel,
|
||||
label,
|
||||
dynamicRules,
|
||||
required,
|
||||
} = props.schema;
|
||||
|
||||
if (isFunction(dynamicRules)) {
|
||||
return dynamicRules(unref(getValuesRef));
|
||||
}
|
||||
|
||||
const rules: ValidationRule[] = cloneDeep(defRules);
|
||||
let rules: ValidationRule[] = cloneDeep(defRules);
|
||||
|
||||
if ((!rules || rules.length === 0) && required) {
|
||||
rules = [{ required }];
|
||||
}
|
||||
|
||||
const requiredRuleIndex: number = rules.findIndex(
|
||||
(rule) => Reflect.has(rule, 'required') && !Reflect.has(rule, 'validator')
|
||||
);
|
||||
|
@ -112,6 +112,8 @@ export interface FormSchema {
|
||||
component: ComponentType;
|
||||
// 组件参数
|
||||
componentProps?: any;
|
||||
// 必填
|
||||
required?: boolean;
|
||||
|
||||
// 校验规则
|
||||
rules?: RuleObject[];
|
||||
|
@ -24,7 +24,7 @@
|
||||
colProps: {
|
||||
span: 8,
|
||||
},
|
||||
rules: [{ required: true }],
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
field: 'field2',
|
||||
@ -33,7 +33,7 @@
|
||||
colProps: {
|
||||
span: 8,
|
||||
},
|
||||
rules: [{ required: true }],
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
field: 'field3',
|
||||
@ -42,7 +42,7 @@
|
||||
colProps: {
|
||||
span: 8,
|
||||
},
|
||||
rules: [{ required: true }],
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
field: 'field4',
|
||||
@ -65,7 +65,7 @@
|
||||
},
|
||||
],
|
||||
},
|
||||
rules: [{ required: true }],
|
||||
rules: [{ required: true, message: '请输入aa' }],
|
||||
},
|
||||
{
|
||||
field: 'field5',
|
||||
|
Loading…
Reference in New Issue
Block a user