Skip to content

Instantly share code, notes, and snippets.

@martindsouza
Last active September 1, 2022 07:25
Show Gist options
  • Save martindsouza/e03b97ca7ac25ba5d5286a647187bca6 to your computer and use it in GitHub Desktop.
Save martindsouza/e03b97ca7ac25ba5d5286a647187bca6 to your computer and use it in GitHub Desktop.
var changedObjects = [];
// inputs
for (input of document.getElementsByTagName("input")){
var changed = false;
switch (input.type) {
case 'hidden':
case 'text':
if (input.value != input.defaultValue){
changed = true;
}
break;
case 'radio':
case 'checkbox':
if (input.checked != input.defaultChecked){
changed = true;
}
}
if (changed){
changedObjects.push(input);
}
} // inputs
// textareas
for (textarea of document.getElementsByTagName("textarea")){
if (textarea.value != textarea.defaultValue){
changedObjects.push(textarea);
}
} // textarea
// Select Lists
for (select of document.getElementsByTagName("select")){
if (!select.options[select.selectedIndex].defaultSelected){
changedObjects.push(select);
}
}// select
console.log('Changed', changedObjects)
@santu1544
Copy link

Hi Martin - per your suggestions in your blog post, I drafted the following.

var changedObjects = [];

allItems = apex.page.forEachPageItem;
allItems(
  $("#wwvFlowForm"),
  function (el, name) {
    if (
      apex.item(name).isChanged() &&
      !apex.item(name).element[0].classList.value.includes("js-ignoreChange")
    ) {
      changedObjects.push(el);
    }
  },
  true
);

console.log("Changed", changedObjects);

I tested it and the above code appears to work with more item types. I also enhanced it to not include items for which "warn on unsaved changes" has been turned off.

It's not working for type "Number Field" items.

@hhudson
Copy link

hhudson commented Jun 21, 2021

Hi Martin - per your suggestions in your blog post, I drafted the following.

var changedObjects = [];

allItems = apex.page.forEachPageItem;
allItems(
  $("#wwvFlowForm"),
  function (el, name) {
    if (
      apex.item(name).isChanged() &&
      !apex.item(name).element[0].classList.value.includes("js-ignoreChange")
    ) {
      changedObjects.push(el);
    }
  },
  true
);

console.log("Changed", changedObjects);

I tested it and the above code appears to work with more item types. I also enhanced it to not include items for which "warn on unsaved changes" has been turned off.

It's not working for type "Number Field" items.

I'm not able to reproduce your bug - my demo application (which uses this code) features a number field : https://apex.oracle.com/pls/apex/haydenhhudson/r/warn-on-unsaved-changes-plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment