From 69c69edbea4ad82a27912762ccf47a19eb988af5 Mon Sep 17 00:00:00 2001 From: Rodrigo Martinez Date: Mon, 13 Nov 2017 09:37:16 -0300 Subject: [PATCH 1/2] Update disable elements on form submit so that the only step that gets executed after serialization of form/button is the disabled property set. This improves visual results on iPad+Safari --- src/rails.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/rails.js b/src/rails.js index 7eee3906..7165ea0a 100644 --- a/src/rails.js +++ b/src/rails.js @@ -244,6 +244,8 @@ rails.formElements(form, rails.disableSelector).each(function() { rails.disableFormElement($(this)); }); + // Slight timeout so that the submit button gets properly serialized + setTimeout(function(){ rails.disableFormElementsDisableProp(form); }, 13); }, disableFormElement: function(element) { @@ -257,14 +259,19 @@ element[method](replacement); } - element.prop('disabled', true); - element.data('ujs:disabled', true); }, - /* Re-enables disabled form elements: - - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`) - - Sets disabled property to false - */ + disableFormElementsDisableProp: function (form) { + rails.formElements(form, rails.disableSelector).each(function () { + $(this).prop('disabled', true); + $(this).data('ujs:disabled', true); + }); + }, + + /* Re-enables disabled form elements: + - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`) + - Sets disabled property to false + */ enableFormElements: function(form) { rails.formElements(form, rails.enableSelector).each(function() { rails.enableFormElement($(this)); @@ -513,8 +520,7 @@ return false; } else { - // Slight timeout so that the submit button gets properly serialized - setTimeout(function(){ rails.disableFormElements(form); }, 13); + rails.disableFormElements(form); } }); From 412260d4c0df74a78493d256dab51175e3ed7999 Mon Sep 17 00:00:00 2001 From: Rodrigo Martinez Date: Mon, 13 Nov 2017 09:47:22 -0300 Subject: [PATCH 2/2] Add additional style class when disabling elements for when it's available --- src/rails.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rails.js b/src/rails.js index 7165ea0a..850a876f 100644 --- a/src/rails.js +++ b/src/rails.js @@ -259,6 +259,8 @@ element[method](replacement); } + // Enhances visual experience when disabled class is styled + element.addClass('disabled'); }, disableFormElementsDisableProp: function (form) {