Skip to content

Commit

Permalink
Fix execute actions for new saved record in form
Browse files Browse the repository at this point in the history
Fixes related to issue #110
  • Loading branch information
itsmemyk08 committed Jun 8, 2023
1 parent ca51dc2 commit 94e52db
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions axelor-front/src/views/form/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ function FormContainer({
get,
set,
record: DataRecord | null,
options?: { readonly?: boolean; refresh?: boolean }
options?: { readonly?: boolean; isNew?: boolean }
) => {
const id = String(record?.id ?? "");
const prev = get(formAtom);
const action = record ? onLoadAction : onNewAction;
const { refresh = true, ...props } = { readonly, ...options };
const { isNew, ...props } = { readonly, ...options };

record = record ?? {};
record =
Expand All @@ -255,7 +255,7 @@ function FormContainer({
original: { ...record },
});

if (action) {
if (action && !isNew) {
// execute action
await actionExecutor.execute(action);

Expand All @@ -278,7 +278,7 @@ function FormContainer({
}
}

if (refresh) {
if (!isNew) {
const event = new CustomEvent("form:refresh", { detail: tabId });
document.dispatchEvent(event);
}
Expand Down Expand Up @@ -366,17 +366,16 @@ function FormContainer({

res = { ...dummy, ...res }; // restore dummy values

let refresh = true;
const isNew = vals.id !== res.id;
// new record save
if (vals.id !== res.id) {
refresh = false;
if (isNew) {
setViewProps((props) => ({
...props,
fetched: { ...res, $$fetched: true },
fetched: res,
}));
}

doEdit(res, { readonly, refresh });
doEdit(res, { readonly, isNew });

return res;
},
Expand Down Expand Up @@ -530,7 +529,7 @@ function FormContainer({
const recId = rec.id ?? 0;
const action = recId > 0 ? onLoadAction : onNewAction;

if (action && !rec.$$fetched) {
if (action) {
await actionExecutor.execute(action);
}
},
Expand Down

0 comments on commit 94e52db

Please sign in to comment.