Merge pull request #4062 from ssilvert/dbl-click
KEYCLOAK-4121: Prevent double form submission
This commit is contained in:
commit
1385d3c219
1 changed files with 16 additions and 2 deletions
|
@ -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')) {
|
||||
|
|
Loading…
Reference in a new issue