Merge branch 'main' into next

This commit is contained in:
nocobase[bot] 2025-04-24 01:54:43 +00:00
commit c6935a8923
3 changed files with 37 additions and 4 deletions

View File

@ -97,6 +97,30 @@ const filterValue = (value) => {
return obj; return obj;
}; };
function getFilteredFormValues(form) {
const values = _.cloneDeep(form.values);
const allFields = [];
form.query('*').forEach((field) => {
if (field) {
allFields.push(field);
}
});
const readonlyPaths = allFields
.filter((field) => field?.componentProps?.readOnlySubmit)
.map((field) => {
const segments = field.path?.segments || [];
if (segments.length <= 1) {
return segments.join('.');
}
return segments.slice(0, -1).join('.');
});
for (const path of readonlyPaths) {
_.unset(values, path);
}
return values;
}
export function getFormValues({ export function getFormValues({
filterByTk, filterByTk,
field, field,
@ -124,7 +148,7 @@ export function getFormValues({
} }
} }
return form.values; return getFilteredFormValues(form);
} }
export function useCollectValuesToSubmit() { export function useCollectValuesToSubmit() {

View File

@ -34,7 +34,7 @@ import useServiceOptions, { useAssociationFieldContext } from './hooks';
const removeIfKeyEmpty = (obj, filterTargetKey) => { const removeIfKeyEmpty = (obj, filterTargetKey) => {
if (!obj || typeof obj !== 'object' || !filterTargetKey || Array.isArray(obj)) return obj; if (!obj || typeof obj !== 'object' || !filterTargetKey || Array.isArray(obj)) return obj;
return !obj[filterTargetKey] ? null : obj; return !obj[filterTargetKey] ? undefined : obj;
}; };
export const AssociationFieldAddNewer = (props) => { export const AssociationFieldAddNewer = (props) => {
@ -106,8 +106,13 @@ const InternalAssociationSelect = observer(
useEffect(() => { useEffect(() => {
const initValue = isVariable(field.value) ? undefined : field.value; const initValue = isVariable(field.value) ? undefined : field.value;
const value = Array.isArray(initValue) ? initValue.filter(Boolean) : initValue; const value = Array.isArray(initValue) ? initValue.filter(Boolean) : initValue;
setInnerValue(value); const result = removeIfKeyEmpty(value, filterTargetKey);
}, [field.value]); setInnerValue(result);
if (!isEqual(field.value, result)) {
field.value = result;
}
}, [field.value, filterTargetKey]);
useEffect(() => { useEffect(() => {
const id = uid(); const id = uid();
form.addEffects(id, () => { form.addEffects(id, () => {

View File

@ -101,6 +101,10 @@ const useLazyLoadDisplayAssociationFieldsOfForm = () => {
field.value = null; field.value = null;
} else { } else {
field.value = result; field.value = result;
field.componentProps = {
...field.componentProps,
readOnlySubmit: true,
}; // 让它不参与提交
} }
}); });
}) })