我正在尝试使用Angular 1.1.1和Ionic来验证表单。角度验证(如果需要的字段为空,则无法到达控制器)
有许多“钱包”,用户需要发送一个新的“价值”到每个钱包。钱包还有一个指定的以前的值。验证应检查是否填写了所有输入字段,以及新值是否大于先前值。
我的形式(的index.html):
<form name="myForm" ng-submit="sendValues(wallets)" ng-controller="valuesCtrl">
<div class="row" ng-repeat="wallet in wallets">
<div class="col item item-input-inset">
<label class="item-input-wrapper item-text-wrap">
<input name="wallet_{{wallet.id}}" type="number" ng-model="wallet.value" type="text" required/>
</label>
<span ng-show="myForm.wallet_{{item.id}}.$error.required">!!!</span>
</div>
<div class="col item">{{ wallet.previous }}</div>
</div>
<button class="button" type="submit">Submit</button>
</form>
它导致始终显示 “!”即使用户尚未提交表单,也会出现空输入错误。我试图在控制器中使用$scope.myForm.submitted=true;
,但问题是只有在填写完所有字段后才会到达控制器。
我控制器(values.js):
'Use Strict';
angular.module('App')
.controller('valuesCtrl', function($scope, $localStorage, UserService, $state) {
$scope.sendValues = function(wallets){
debugger;
...
})
谁能帮我弄清楚为什么我不能看到调试窗口,如果不是所有的领域都与信息? 你能建议如何进行自定义验证吗? (新值应比以前更大)
我无法设置'''myForm。$ submitted == true'''在所有字段不存在的情况下 – Zelenka
如果您不想使用'ng-submit' –
谢谢,我不知道'novalidate'。 – Zelenka