diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ee52d51..5693b61f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Adminer dev +- Confirm before exiting edited edit form - Display collation at table structure if different from table - PostgreSQL: Display auto_increment of inserted rows - PostgreSQL: Display description of system variables diff --git a/adminer/call.inc.php b/adminer/call.inc.php index a9df194d..5ae5fa44 100644 --- a/adminer/call.inc.php +++ b/adminer/call.inc.php @@ -81,6 +81,7 @@ if ($in) { echo "\n"; } echo "\n"; + echo script("setupEditChange(qsl('form'));"); } ?>
diff --git a/adminer/include/html.inc.php b/adminer/include/html.inc.php index 6bbd9299..ec338e16 100644 --- a/adminer/include/html.inc.php +++ b/adminer/include/html.inc.php @@ -337,7 +337,7 @@ function input($field, $value, $function, $autofocus = false) { $first++; } if ($first) { - echo script("mixin(qsl('td'), {onchange: partial(skipOriginal, $first), oninput: function () { this.onchange(); }});"); + echo script("mixin(qsl('td'), {oninput: partial(skipOriginal, $first)});"); } } } @@ -513,6 +513,7 @@ function edit_form($table, $fields, $row, $update) { ; } echo "\n"; + echo script("setupEditChange(qsl('form'));"); } echo "
\n"; if ($fields) { diff --git a/adminer/static/functions.js b/adminer/static/functions.js index 58b8306a..8bd450dc 100644 --- a/adminer/static/functions.js +++ b/adminer/static/functions.js @@ -575,6 +575,29 @@ function fieldChange() { +let editChanged; + +/** Setup saving editChanged on form fields +* @this HTMLFormElement +*/ +function setupEditChange(form) { + for (const el of qsa('input, select, textarea', form)) { + el.addEventListener('change', () => { + editChanged = true; + }); + } + form.onsubmit = () => { + editChanged = null; // false doesn't work in Chrome + } +} + +onbeforeunload = () => { + // all modern browsers ignore string returned from here + return editChanged; +}; + + + /** Create AJAX request * @param string * @param function (XMLHttpRequest)