Skip to content

Commit

Permalink
Merge branch 'master' into feature/placeholder-option
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-epineer authored Apr 25, 2019
2 parents 901acae + 9254315 commit 7dc2a4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions resources/js/confirm-leave-page.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion resources/js/kontour.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7dc2a4e

Please sign in to comment.