gpt4 book ai didi

javascript - 在 ngTagsInput 中如何显示不同情况的验证消息?

转载 作者:行者123 更新时间:2023-11-27 23:54:02 26 4
gpt4 key购买 nike

我正在使用 ngTagsInput Angular 插件来获取多个电子邮件 ID。下面是我的代码:

<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。

以上案例运行良好。但是,我想根据上面发生的一种情况动态显示错误消息。请帮帮我!

最佳答案

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;

})

关于javascript - 在 ngTagsInput 中如何显示不同情况的验证消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32422861/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com