diff --git a/resources/js/confirm-leave-page.js b/resources/js/confirm-leave-page.js index 02394ce4..83552003 100644 --- a/resources/js/confirm-leave-page.js +++ b/resources/js/confirm-leave-page.js @@ -1,18 +1,21 @@ +/*! @preserve + * If you submit via ajax, you should removeAttribute("data-kontour-dirty") if the request succeedes. + */ + // Mark inputs as dirty when they change ["input", "change"].forEach(function(eventname) { document.body.addEventListener(eventname, function(event) { - event.target.setAttribute("data-kontour-dirty", "true"); + if (event.target.form && event.target.type != "search") { + event.target.setAttribute("data-kontour-dirty", "true"); + } }); }); // Mark dirty inputs as saving when their form is submitted -// If you submit via ajax, you may want to set them back to dirty again if the request fails document.body.addEventListener("submit", function(event) { - event.target - .querySelectorAll('[data-kontour-dirty="true"]') - .forEach(function(element) { - element.setAttribute("data-kontour-dirty", "saving"); - }); + [...event.target.elements].forEach(function(input) { + input.setAttribute("data-kontour-dirty", "saving"); + }); }); // Alert user if any inputs on the page are dirty before leaving diff --git a/resources/js/kontour.js b/resources/js/kontour.js index 100082e7..fc03cf8f 100644 --- a/resources/js/kontour.js +++ b/resources/js/kontour.js @@ -1 +1 @@ -function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function _arrayWithoutHoles(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e