1

plunkerにいくつかのサンプルを書きました。ユーザーが入力を離れたときに入力を検証する必要があります。これに使いng-model-options="{ updateon: 'blur'}"ました。正常に動作しますが、これは検証ng-minlengthには適用されません。ng-required

4

3 に答える 3

1

(混乱を招くため、別の例を編集して削除しました)

$touched を試してみてください。

私はあなたのプランクをフォークしました

http://plnkr.co/edit/tt5A1DUjmq07TiEKhtNP?p=preview

また、2 つのフィールドを追加して、動作を確認できるようにしました。たとえば、一方から他方へのタブです。

HTML

<input name="inputA" type="text" ng-model="valueA" ng-required="true" ng-model-options="{updateOn: 'blur'}" ng-minlength="3" />
<span ng-if="myForm.inputA.$error.required && myForm.inputA.$touched">You didn't enter a value</span>
<span ng-if="myForm.inputA.$error.minlength">to short</span>
<br/>
<input name="inputB" type="text" ng-model="valueB" ng-required="true" ng-model-options="{updateOn: 'blur'}" ng-minlength="3" />
<span ng-if="myForm.inputB.$error.required && myForm.inputB.$touched">You didn't enter a value</span>
<span ng-if="myForm.inputB.$error.minlength">to short</span>
于 2015-04-08T07:48:59.150 に答える
1

updateOnを使用する必要があると思います

ng-model-options="{updateOn: 'blur'}"

一緒に

novalidate=""

フォーム上

于 2016-09-23T10:16:31.463 に答える