Skip to content

Commit 184902c

Browse files
authored
Merge pull request #8705 from ProcessMaker/bugfix/FOUR-28985
bugfix/FOUR-28985 `Submit action` is not working when a `new Inbox rule` is created
2 parents 647527b + f19c034 commit 184902c

1 file changed

Lines changed: 117 additions & 72 deletions

File tree

Lines changed: 117 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,135 @@
11
<template>
22
<div>
33
<b-embed
4+
ref="preview"
45
:src="linkTasks"
5-
@load="loaded()"
66
:disable-interstitial="true"
7-
ref="preview"
8-
:event-parent-id="_uid" />
7+
:event-parent-id="_uid"
8+
@load="loaded()"
9+
/>
910
</div>
1011
</template>
1112

12-
1313
<script>
14-
export default {
15-
props: {
16-
taskId: {
17-
type: Number,
18-
default: null
19-
},
20-
inboxRuleData: {
21-
type: Object,
22-
default: null
23-
},
24-
propInboxQuickFill: {
25-
type: Object,
26-
default: null
27-
},
14+
export default {
15+
props: {
16+
taskId: {
17+
type: Number,
18+
default: null,
2819
},
29-
data() {
30-
return {
31-
formData: {}
32-
};
20+
inboxRuleData: {
21+
type: Object,
22+
default: null,
3323
},
34-
computed: {
35-
linkTasks() {
36-
return `/tasks/${this.taskId}/edit/preview?dispatchSubmit=1&alwaysAllowEditing=1&disableInterstitial=1`;
37-
},
38-
iframeContentWindow() {
39-
return this.$refs['preview'].firstChild.contentWindow;
40-
}
24+
propInboxQuickFill: {
25+
type: Object,
26+
default: null,
4127
},
42-
watch: {
43-
formData() {
44-
this.$emit("data", this.formData);
45-
},
46-
propInboxQuickFill() {
47-
this.formData = _.merge({}, this.formData, this.propInboxQuickFill);
48-
this.iframeContentWindow.location.reload();
49-
}
28+
},
29+
data() {
30+
return {
31+
formData: {},
32+
lastClickedButton: null,
33+
};
34+
},
35+
computed: {
36+
linkTasks() {
37+
return `/tasks/${this.taskId}/edit/preview?dispatchSubmit=1&alwaysAllowEditing=1&disableInterstitial=1`;
38+
},
39+
iframeContentWindow() {
40+
return this.$refs.preview.firstChild.contentWindow;
41+
},
42+
},
43+
watch: {
44+
formData() {
45+
this.$emit("data", this.formData);
5046
},
51-
mounted() {
52-
this.receiveEvent('dataUpdated', (data) => {
53-
this.formData = data;
47+
propInboxQuickFill() {
48+
this.formData = _.merge({}, this.formData, this.propInboxQuickFill);
49+
this.iframeContentWindow.location.reload();
50+
},
51+
},
52+
mounted() {
53+
this.receiveEvent("dataUpdated", (data) => {
54+
this.formData = data;
55+
});
56+
this.receiveEvent("formSubmit", (data) => {
57+
// Use buttonInfo from event if it's a valid object, otherwise use lastClickedButton
58+
let submitData = null;
59+
if (data && typeof data === "object" && !Array.isArray(data)) {
60+
submitData = data;
61+
} else if (this.lastClickedButton && this.lastClickedButton.label) {
62+
// Fallback: use button info captured from iframe click listener
63+
submitData = {
64+
name: this.lastClickedButton.name,
65+
label: this.lastClickedButton.label,
66+
value: this.lastClickedButton.value,
67+
};
68+
}
69+
this.$emit("submit", submitData);
70+
});
71+
this.receiveEvent("taskReady", () => {
72+
this.sendEvent("fillDataOverwriteExistingFields", this.inboxRuleData);
73+
// Setup click listener for submit buttons in iframe after task is ready
74+
this.$nextTick(() => {
75+
this.setupButtonClickListener();
5476
});
55-
this.receiveEvent('formSubmit', (data) => {
56-
this.$emit("submit", data);
77+
});
78+
},
79+
methods: {
80+
eraseData() {
81+
this.sendEvent("eraseData", true);
82+
},
83+
reload() {
84+
this.formData = {};
85+
this.iframeContentWindow.location.reload();
86+
},
87+
loaded() {
88+
// eslint-disable-next-line no-underscore-dangle
89+
this.iframeContentWindow.event_parent_id = this._uid;
90+
this.sendEvent("sendValidateForm", false);
91+
},
92+
sendEvent(name, data) {
93+
const event = new CustomEvent(name, {
94+
detail: data,
5795
});
58-
this.receiveEvent('taskReady', () => {
59-
this.sendEvent("fillDataOverwriteExistingFields", this.inboxRuleData);
96+
this.iframeContentWindow.dispatchEvent(event);
97+
},
98+
receiveEvent(name, callback) {
99+
window.addEventListener(name, (event) => {
100+
// eslint-disable-next-line no-underscore-dangle
101+
if (event.detail.event_parent_id !== this._uid) {
102+
return;
103+
}
104+
callback(event.detail.data);
60105
});
61106
},
62-
methods: {
63-
eraseData() {
64-
this.sendEvent("eraseData", true);
65-
},
66-
reload() {
67-
this.formData = {};
68-
this.iframeContentWindow.location.reload();
69-
},
70-
loaded() {
71-
this.iframeContentWindow.event_parent_id = this._uid;
72-
this.sendEvent("sendValidateForm", false);
73-
},
74-
sendEvent(name, data) {
75-
const event = new CustomEvent(name, {
76-
detail: data
77-
});
78-
this.iframeContentWindow.dispatchEvent(event);
79-
},
80-
receiveEvent(name, callback) {
81-
window.addEventListener(name, (event) => {
82-
if (event.detail.event_parent_id !== this._uid) {
83-
return;
107+
setupButtonClickListener() {
108+
try {
109+
const iframeDoc = this.iframeContentWindow.document;
110+
// Listen for clicks on submit buttons in the iframe
111+
iframeDoc.addEventListener("click", (event) => {
112+
const button = event.target.closest("button");
113+
if (button) {
114+
// Check if this is a submit button (has btn-primary class or is inside form-group)
115+
const isSubmitButton = button.classList.contains("btn-primary")
116+
|| button.classList.contains("btn-secondary")
117+
|| button.closest(".form-group");
118+
if (isSubmitButton) {
119+
this.lastClickedButton = {
120+
name: button.getAttribute("name") || null,
121+
label: button.textContent?.trim() || null,
122+
value: button.value || null,
123+
};
124+
}
84125
}
85-
callback(event.detail.data);
86-
});
87-
},
88-
}
89-
}
90-
</script>
126+
}, true);
127+
} catch (e) {
128+
// Cross-origin restrictions may prevent access to iframe content
129+
// eslint-disable-next-line no-console
130+
console.warn("Could not setup button click listener in iframe:", e.message);
131+
}
132+
},
133+
},
134+
};
135+
</script>

0 commit comments

Comments
 (0)