Skip to content

Commit

Permalink
fix bug enter key down submit
Browse files Browse the repository at this point in the history
  • Loading branch information
why520crazy committed Jul 13, 2017
1 parent 9cc7aa7 commit 3cd36a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
27 changes: 16 additions & 11 deletions w5cValidator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! ng-w5c-validator v2.5.4 2017-06-15 */
/*! angular-w5c-validator v2.5.5 2017-07-13 */
(function(){
var w5cValidator = angular.module("w5c.validator", ["ng"])
.provider('w5cValidator', [function () {
Expand Down Expand Up @@ -200,9 +200,10 @@
w5cValidator, $parse, $timeout) {
var _self = this;
var _formElem = $element[0];
this.needBindKeydown = false;
this.formCtrl = null;
this.submitSuccessFn = null;
// Enter 键提交
this.needBindKeydown = false;
this.enterKeydownFn = null;
this.validElements = [];

this.setElementErrorMessage = function (elemName, errorMessage) {
Expand Down Expand Up @@ -300,13 +301,16 @@
button[0].focus();
}
currentInput.focus();
doValidate();
event.preventDefault();
if (formCtrl.$valid && angular.isFunction(_self.submitSuccessFn)) {
$scope.$apply(function () {
_self.submitSuccessFn($scope, {$event: event});
});
if(angular.isFunction(_self.enterKeydownFn)){
_self.enterKeydownFn(event);
}
//
// if (formCtrl.$valid && angular.isFunction(_self.submitSuccessFn)) {
// $scope.$apply(function () {
// _self.submitSuccessFn($scope, {$event: event});
// });
// }
}
}
});
Expand Down Expand Up @@ -479,7 +483,7 @@
link: function (scope, element, attr, ctrl) {
var validSuccessFn = $parse(attr.w5cFormSubmit);
var errorCallback = $parse(attr.errorCallback);
element.bind("click", function (event) {
var submitFn = function (event) {
ctrl.doValidate(function () {
validSuccessFn(scope, {$event: event});
}, function ($errors, invalidElements) {
Expand All @@ -491,9 +495,10 @@
});
}
});
});
};
element.bind("click", submitFn);
ctrl.needBindKeydown = true;
ctrl.submitSuccessFn = scope.w5cFormSubmit;
ctrl.enterKeydownFn = submitFn;
}
};
}])
Expand Down
Loading

0 comments on commit 3cd36a4

Please sign in to comment.