我有一个简单的表单,我需要验证。如何在没有按钮(提交)的情况下验证它?
<form name="myForm" novalidate>
<fieldset>
<legend>Info</legend>
<div>
<label for="name">Name:</label>
<input type="text" name="name" id="name" ng-model="myName" required/>
</div>
<div>
<label for="pass">Password:</label>
<input type="password" name="pass" id="pass" ng-model="myPass" required/>
</div>
<div>
<label for="email">Email:</label>
<input type="email" name="email" id="email" ng-model="myMail" required/>
</div>
<div>
<label for="birth">Date of birth:</label>
<input type="date" id="birth" name="birth" ng-model="date"/>
</div>
</fieldset>
</form>
&#13;
答案 0 :(得分:0)
默认情况下,只要数据发生变化(无论是来自模型还是基于直接用户输入),Angular表单验证都会自动触发,它与表单提交无关。您可以使用SELECT
f1.id,
f1.parent_id,
f1.name AS 'default_name',
f2.name AS 'translated_name'
FROM
h_itsm_faqs f1 LEFT JOIN h_itsm_faqs f2 ON (f1.parent_id = f2.parent_id AND f2.language LIKE 'es')
WHERE
f1.language = 'default'
修改哪些事件触发此事件,如
ng-model-options
如果您需要创建自己的自定义验证器,请将其添加到<input ng-model-options="{
updateOn: 'default blur',
debounce: { default: 500, blur: 0 }
}" ...>
或ngModelController.$validators
,例如:
$asyncValidators
<input type="text" name="name" id="name" ng-model="myName" validatename required/>
我相信你也可以通过调用app.directive('validatename', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$validators.validatename = function(modelValue, viewValue) {
if (ctrl.$isEmpty(modelValue)) {
return true;
}
if (viewValue === "Zuul") {
return true;
}
return false; // There is no Dana only Zuul
};
}
};
});
以编程方式触发验证,但这很少是必要的。