Merge pull request #4062 from ssilvert/dbl-click

KEYCLOAK-4121: Prevent double form submission
This commit is contained in:
Stian Thorgersen 2017-04-25 08:57:15 +02:00 committed by GitHub
commit 1385d3c219

View file

@ -2168,15 +2168,29 @@ module.directive('kcEnter', function() {
};
});
module.directive('kcSave', function ($compile, Notifications) {
module.directive('kcSave', function ($compile, $timeout, Notifications) {
var clickDelay = 500; // 500 ms
return {
restrict: 'A',
link: function ($scope, elem, attr, ctrl) {
elem.addClass("btn btn-primary");
elem.attr("type","submit");
elem.bind('click', function() {
var disabled = false;
elem.on('click', function(evt) {
if ($scope.hasOwnProperty("changed") && !$scope.changed) return;
// KEYCLOAK-4121: Prevent double form submission
if (disabled) {
evt.preventDefault();
evt.stopImmediatePropagation();
return;
} else {
disabled = true;
$timeout(function () { disabled = false; }, clickDelay, false);
}
$scope.$apply(function() {
var form = elem.closest('form');
if (form && form.attr('name')) {