Hello there,
I am trying to include the Saving of an iframe form into the Saving of my main form.
So by saving the main Form, the iframe form should also be saved, ideally when leaving the main form there should appear a warning, if unchanged edits in the iframe form exist.
I hope this is possible with BeforeSave, but regarding the actual code I am in a dead end, hopefully someone here can help me out.
Best regards
marcus
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
saving iframe
-
- nuBuilder Team
- Posts: 4302
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 445 times
- Contact:
Re: saving iframe
Hi,
My idea is that when the save button is clicked in the main form, a check is done in nuBeforeSave() to see if the iframe is saved.
If it is not saved, the saving of the iFrame is initiated and then in the iFrame, the save of the main form is triggered in the nuAfterSave() event.
PS: If your nuBuilder version doesn't include the nuGetStorageItem(), nuGetStorageItem() functions, you can either update it or use the sessionStorage objects directly
JS Custom Code in main form:
JS Custom Code in iFrame:
My idea is that when the save button is clicked in the main form, a check is done in nuBeforeSave() to see if the iframe is saved.
If it is not saved, the saving of the iFrame is initiated and then in the iFrame, the save of the main form is triggered in the nuAfterSave() event.
PS: If your nuBuilder version doesn't include the nuGetStorageItem(), nuGetStorageItem() functions, you can either update it or use the sessionStorage objects directly
JS Custom Code in main form:
Code: Select all
nuSetStorageItem('iframe_saving_status', null);
function iFrameUnsaved() {
let c = 0;
$.each($('iframe'), function() {
let t = $(this)[0];
try {
if (typeof t.contentWindow['nuIsSaved'] === 'function') {
if (!t.contentWindow.nuIsSaved()) {
c++;
}
}
} catch (e) {
// catch "DOMException: Blocked a frame with origin"
}
})
return c;
}
function nuBeforeSave() {
if (nuGetStorageItem('iframe_saving_status') === null && iFrameUnsaved() > 0) {
nuSetStorageItem('iframe_saving_status', 'saving')
document.getElementById("run_iframe").contentWindow.nuSaveAction(); // <------ replace run_iframe with you iframe obj id
return false;
} else {
return true;
}
}
JS Custom Code in iFrame:
Code: Select all
function nuAfterSave() {
if (nuGetStorageItem('iframe_saving_status') == 'saving') {
nuSetStorageItem('iframe_saving_status', 'saved');
parent.nuSaveAction();
}
}