我有一个有效的角形,直到一个字段变得可见,当它显示为真时,jquery validate不会在单击按钮中调用sumbitHandler回调(它只需点击2次)
下面是表单,当单击href时,字段 someName 变为可见,此后需要2次点击才能调用submitHandler以及其他问题。直到href或者再次点击它来切换回来,它工作正常。
<form accept-charset="UTF-8" id="some-form"><div class="form-group" ng-show="config.showFormToggle">
<a href ng-click="toggleOldNew()">{{config.nonDefault === true ? "Switch to Old form" : "Switch to New Form "}} </a>
</div>
<div class="form-group" ng-show="config.nonDefault">
<label for="someName">some Name</label>
<input type="text" class="form-control" id="someName" name="someName" ng-model="values.someName" ng-change="update()">
</div>
<div class="form-group">
<label for="items">Items</label>
<input type="text" id="items" name="items" ng-model="values.items" ng-change="update()">
</div>
<div class="form-group">
<button class="btn btn-primary pull-right has-spinner" ng-click="callService()">
<span class="spinner glyphicon glyphicon-refresh glyphicon-refresh-animate"></span>
Run
</button>
</div>
下面是按钮单击调用的方法,它在字段1中循环逗号分隔值并创建一个TaskRunner并调用它的run方法
$scope.callService= function (){
var items = $scope.values.items ? $scope.values.items.split(/\s*,\s*/) : [];
items.forEach(function (item) {
var index=0;
//creates a TaskRunner(item.items.length,index) to perform some action on this item ,increment index
taskRunner.run();
}
}
$scope.createTaskRunner = function (item, total, current) {
var taskRunner=new TaskRunner({itemToRun:item,totalItem:total,currentItem:current});
if(current === 1) {
runner.validate= function (success) {
form.validate({
rules: rules,
submitHandler: success
});
};
return taskRunner;
}
这将启动任务,并在此调用validate,预计将调用submitHandler
SomeRunner.prototype.run = function () {
var self = this;
var handler = function () {
return self.submitHandler();
};
if(self.validate) {
self.validate(handler);
} else {
// no validation to be done just call the submit handler
handler();
}
};
代码被修剪为可读。因为表单在初始状态下工作,并且在config.nonDefault为true且someName字段变为可见时不起作用。在这种情况下,submitHandler需要单击2次第一次调用validate时不会调用submitHandler,当再次单击该按钮时,它会调用它。 这是使用Angular(1.2.4)的Jquery验证插件(1.15.1)的任何已知问题吗?