我正在使用带有一些客户端输入验证的angularjs编写一个简单的登录表单,以检查用户名和密码是否为空且长度不超过三个字符。请参见以下代码:
<form name="loginform" novalidate ng-submit="login.submit()" class="css-form">
<fieldset>
<div class="control-group input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input type="text" ng-model="login.username" name="username" required ng-minlength="3" placeholder="username" />
</div>
<div class="control-group input-prepend">
<span class="add-on"><i class="icon-lock"></i></span>
<input type="password" ng-model="login.password" name="password" required ng-minlength="3" placeholder="" />
</div>
<div class="control-group">
<input class="btn" type="submit" value="Log in">
</div>
</fieldset>
</form>
和控制器:
var controller = function($scope) {
$scope.login = {
submit: function() {
Console.info($scope.login.username + ' ' + $scope.login.password);
}
}
};
问题是login.submit
即使输入无效,该函数也会被调用。有可能防止这种行为吗?
附带一提,我可以提到我也使用了bootstrap和requirejs。