Page 1 of 1
saving iframe
Posted: Fri Jun 24, 2022 2:34 pm
by marcus
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
Re: saving iframe
Posted: Fri Jun 24, 2022 3:18 pm
by kev1n
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:
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();
}
}
Re: saving iframe
Posted: Mon Jul 18, 2022 8:58 pm
by kev1n
Did that help?