fix(BasicForm): when value is 0 or false resetFields is not work (#3828)

* fix(BasicForm): when value is 0 or false resetFields is not work

* fix(BasicForm): when value is 0 or false resetFields is not work
This commit is contained in:
zhang 2024-05-11 06:56:36 +08:00 committed by GitHub
parent 478802b426
commit 22052f10f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 24 deletions

View File

@ -100,16 +100,15 @@ export function useFormEvents({
});
}
let constructValue
let constructValue;
const setDateFieldValue = (v) => {
return v ? (_props?.valueFormat ? v : dateUtil(v)) : null;
};
// Adapt date component
if (itemIsDateComponent(schema?.component)) {
constructValue = tryConstructArray(key, values);
if(!!constructValue){
if (constructValue) {
const fieldValue = constructValue || value;
if (Array.isArray(fieldValue)) {
const arr: any[] = [];
@ -147,15 +146,15 @@ export function useFormEvents({
*/
function resetDefaultField(nameList?: NamePath[]) {
if (!Array.isArray(nameList)) {
return
return;
}
if (Array.isArray(nameList) && nameList.length === 0) {
return;
}
const validKeys: string[] = [];
let keys = Object.keys(unref(formModel))
const keys = Object.keys(unref(formModel));
if (!keys) {
return
return;
}
nameList.forEach((key: any) => {
if (keys.includes(key)) {
@ -175,9 +174,9 @@ export function useFormEvents({
return;
}
let fieldList: string[] = isString(fields) ? [fields] : fields;
let fieldList = (isString(fields) ? [fields] : fields) as string[];
if (isString(fields)) {
fieldList = [fields];
fieldList = [fields as string];
}
for (const field of fieldList) {
_removeSchemaByField(field, schemaList);
@ -404,7 +403,7 @@ export function useFormEvents({
resetFields,
setFieldsValue,
scrollToField,
resetDefaultField
resetDefaultField,
};
}
@ -416,7 +415,7 @@ function getDefaultValue(
let defaultValue = cloneDeep(defaultValueRef.value[key]);
const isInput = checkIsInput(schema);
if (isInput) {
return defaultValue || undefined;
return !isNil(defaultValue) ? defaultValue : undefined;
}
if (!defaultValue && schema && checkIsRangeSlider(schema)) {
defaultValue = [0, 0];