Skip to content
Snippets Groups Projects
Commit c67b864e authored by Mike Priscella's avatar Mike Priscella
Browse files

Using a more reliable method to determine whether the form has been updated

parent d1cd896e
No related branches found
Tags 1.0.0-beta2
No related merge requests found
......@@ -13,3 +13,10 @@ use Drupal\Core\Form\FormStateInterface;
function confirm_leave_form_node_form_alter(&$form, FormStateInterface $form_state) {
$form['#attached']['library'][] = 'confirm_leave/confirm-leave';
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function confirm_leave_form_node_edit_form_alter(&$form, FormStateInterface $form_state) {
$form['#attached']['library'][] = 'confirm_leave/confirm-leave';
}
......@@ -14,14 +14,16 @@
*/
Drupal.behaviors.confirmLeave = {
attach: function (context, settings) {
$('form :input').on('change', function (e) {
$('.form-item').on('formUpdated', function (e) {
$('form').addClass('form-updated');
window.onbeforeunload = function (e) {
let dialogText = 'Are you sure?';
e.returnValue = dialogText;
return dialogText;
}
$('.form-submit').on('click', function (e) {
$('#edit-submit').on('click', function (e) {
window.onbeforeunload = null;
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment