1

ngTagsInput複数の電子メール ID を取得するために Angular プラグインを使用しています。以下は私のコードです:

<form name="contact_us" role="form" novalidate enctype="multipart/form-data">
  <div class="form-group">
    <label class="control-label" for="from_email">
      From
    </label>
    <tags-input ng-model="contactUs.emails" type="email" id="from_email"
        placeholder="From" name="from_email"
        allowed-tags-pattern="^[A-Za-z0-9._%+-]+@(?:[A-Za-z0-9-]+.)+[A-Za-z]{2,}" 
        allow-leftover-text="false" ng-required="true" add-on-space="true">
    </tags-input>
    <p class="help-block" style="color:red"
        ng-show="contact_us.from_email.$invalid && (contact_us.$submitted || contact_us.$dirty)">
      Please enter proper email address
    </p>
    <button type="submit" class="btn btn-default" ng-click="Send(contact_us)">
      Send
    </button>
</form>

上記のコード 3 では、次のような検証が追加されています。

  1. 必須フィールドの場合。
  2. フィールドは電子メール ID のみを受け入れる必要があります。
  3. 重複した電子メール ID を許可しないでください。

上記のケースは正常に機能しています。しかし、上記のケースが発生した場合に応じて、エラーメッセージを動的に表示したい。私を助けてください !!!

4

2 に答える 2

1

ngTagsInput は、変更をキャプチャするために以下の属性をサポートし、モデルに追加する前に起動します

on-tag-adding="foo($tag)" 

$scope.foo(function(tag){
   // look for error
     // if found return false

  // change the text of tag
     tag.text='what ever';
     return tag;

})
于 2016-09-12T19:44:07.567 に答える