mirror of
https://gitee.com/bootx/dax-pay-ui.git
synced 2025-09-28 14:41:44 +00:00
feat(form): adding resetSchema method
This commit is contained in:
@@ -168,6 +168,7 @@
|
|||||||
validateFields,
|
validateFields,
|
||||||
getFieldsValue,
|
getFieldsValue,
|
||||||
updateSchema,
|
updateSchema,
|
||||||
|
resetSchema,
|
||||||
appendSchemaByField,
|
appendSchemaByField,
|
||||||
removeSchemaByFiled,
|
removeSchemaByFiled,
|
||||||
resetFields,
|
resetFields,
|
||||||
@@ -230,6 +231,7 @@
|
|||||||
setFieldsValue,
|
setFieldsValue,
|
||||||
resetFields,
|
resetFields,
|
||||||
updateSchema,
|
updateSchema,
|
||||||
|
resetSchema,
|
||||||
setProps,
|
setProps,
|
||||||
removeSchemaByFiled,
|
removeSchemaByFiled,
|
||||||
appendSchemaByField,
|
appendSchemaByField,
|
||||||
|
@@ -65,6 +65,11 @@ export function useForm(props?: Props): UseFormReturnType {
|
|||||||
form.updateSchema(data);
|
form.updateSchema(data);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
resetSchema: async (data: Partial<FormSchema> | Partial<FormSchema>[]) => {
|
||||||
|
const form = await getForm();
|
||||||
|
form.resetSchema(data);
|
||||||
|
},
|
||||||
|
|
||||||
clearValidate: async (name?: string | string[]) => {
|
clearValidate: async (name?: string | string[]) => {
|
||||||
const form = await getForm();
|
const form = await getForm();
|
||||||
form.clearValidate(name);
|
form.clearValidate(name);
|
||||||
|
@@ -137,6 +137,26 @@ export function useFormEvents({
|
|||||||
schemaRef.value = schemaList;
|
schemaRef.value = schemaList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function resetSchema(data: Partial<FormSchema> | Partial<FormSchema>[]) {
|
||||||
|
let updateData: Partial<FormSchema>[] = [];
|
||||||
|
if (isObject(data)) {
|
||||||
|
updateData.push(data as FormSchema);
|
||||||
|
}
|
||||||
|
if (isArray(data)) {
|
||||||
|
updateData = [...data];
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasField = updateData.every((item) => Reflect.has(item, 'field') && item.field);
|
||||||
|
|
||||||
|
if (!hasField) {
|
||||||
|
error(
|
||||||
|
'All children of the form Schema array that need to be updated must contain the `field` field'
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
schemaRef.value = updateData as FormSchema[];
|
||||||
|
}
|
||||||
|
|
||||||
async function updateSchema(data: Partial<FormSchema> | Partial<FormSchema>[]) {
|
async function updateSchema(data: Partial<FormSchema> | Partial<FormSchema>[]) {
|
||||||
let updateData: Partial<FormSchema>[] = [];
|
let updateData: Partial<FormSchema>[] = [];
|
||||||
if (isObject(data)) {
|
if (isObject(data)) {
|
||||||
@@ -227,6 +247,7 @@ export function useFormEvents({
|
|||||||
validateFields,
|
validateFields,
|
||||||
getFieldsValue,
|
getFieldsValue,
|
||||||
updateSchema,
|
updateSchema,
|
||||||
|
resetSchema,
|
||||||
appendSchemaByField,
|
appendSchemaByField,
|
||||||
removeSchemaByFiled,
|
removeSchemaByFiled,
|
||||||
resetFields,
|
resetFields,
|
||||||
|
@@ -31,6 +31,7 @@ export interface FormActionType {
|
|||||||
getFieldsValue: () => Recordable;
|
getFieldsValue: () => Recordable;
|
||||||
clearValidate: (name?: string | string[]) => Promise<void>;
|
clearValidate: (name?: string | string[]) => Promise<void>;
|
||||||
updateSchema: (data: Partial<FormSchema> | Partial<FormSchema>[]) => Promise<void>;
|
updateSchema: (data: Partial<FormSchema> | Partial<FormSchema>[]) => Promise<void>;
|
||||||
|
resetSchema: (data: Partial<FormSchema> | Partial<FormSchema>[]) => Promise<void>;
|
||||||
setProps: (formProps: Partial<FormProps>) => Promise<void>;
|
setProps: (formProps: Partial<FormProps>) => Promise<void>;
|
||||||
removeSchemaByFiled: (field: string | string[]) => Promise<void>;
|
removeSchemaByFiled: (field: string | string[]) => Promise<void>;
|
||||||
appendSchemaByField: (
|
appendSchemaByField: (
|
||||||
|
Reference in New Issue
Block a user