Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use attr to set disabled attribute for a tag, instead of using prop #328

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/rails.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])',

// Form input elements disabled during form submission
disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with], a[data-disable-with]',

// Form input elements re-enabled after form submission
enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled, a[data-disable-with]:disabled',

// Form required input elements
requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
Expand Down Expand Up @@ -182,10 +182,15 @@
*/
disableFormElements: function(form) {
form.find(rails.disableSelector).each(function() {
var element = $(this), method = element.is('button') ? 'html' : 'val';
var element = $(this), method = (element.is('button') || element.is('a')) ? 'html' : 'val';
element.data('ujs:enable-with', element[method]());
element[method](element.data('disable-with'));
element.prop('disabled', true);
if(element.is('a')) {
element.attr('disabled', true);
} else {
element.prop('disabled', true);
}
});
},

Expand All @@ -198,6 +203,11 @@
var element = $(this), method = element.is('button') ? 'html' : 'val';
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
element.prop('disabled', false);
if(element.is('a')) {
element.removeAttr('disabled');
} else {
element.prop('disabled', false);
}
});
},

Expand Down Expand Up @@ -263,6 +273,7 @@
disableElement: function(element) {
element.data('ujs:enable-with', element.html()); // store enabled state
element.html(element.data('disable-with')); // set to disabled state
element.attr('disabled', true);
element.bind('click.railsDisable', function(e) { // prevent further clicking
return rails.stopEverything(e);
});
Expand All @@ -274,6 +285,7 @@
element.html(element.data('ujs:enable-with')); // set to old enabled state
element.removeData('ujs:enable-with'); // clean up cache
}
element.removeAttr('disabled');
element.unbind('click.railsDisable'); // enable element
}

Expand Down Expand Up @@ -390,4 +402,4 @@
});
}

})( jQuery );
})( jQuery );