我是新来的天使。尝试使用引导工具提示实现表单验证。如果输入字段无效并获得焦点,带有工具提示的文本将出现。验证工作正常,即如果输入字段有无效的值,但是工具提示文本没有显示,则输入字段会变红。以下是html:
<form role="form" name="form" ng-controller="registerController">
<div class="col-sm-12">
<div class="form-group" ng-class="{ 'has-error': form.fullName.$invalid && form.fullName.$touched}">
<input class="form-control has-feedback" name="fullName" id="fullName"
type="text"
required
ng-model="fullName"
tooltip="{{form.fullName.$valid ? '' : 'Full name required'}}"
tooltip-trigger="focus"
tooltip-placement="top" />
<span class="glyphicon glyphicon-ok-sign text-success form-control-feedback" aria-hidden="true"
ng-show="form.fullName.$valid"></span>
</div>
</div>
</form>关于额外的信息,我已经包括了以下脚本和css文件:
<script src="../scripts/jquery-2.2.1.min.js"></script>
<link href="../Content/bootstrap.min.css" rel="stylesheet" />
<script src="../scripts/bootstrap.min.js"></script>
<script src="../scripts/angular.min.js"></script>
<script src="../scripts/angular-ui/ui-bootstrap-tpls.min.js"></script>帮我弄清楚我怎么能让它起作用。提前谢谢。
发布于 2016-03-12 06:21:20
如果您使用的是https://angular-ui.github.io/bootstrap/#/tooltip
输入字段应该如下所示:
<input class="form-control has-feedback" name="fullName" id="fullName"
type="text"
required
ng-model="fullName"
uib-tooltip="Full name required"
tooltip-is-open="form.fullName.$invalid"
tooltip-trigger="none"
tooltip-placement="top" />您希望删除内置触发器,将其设置为"none“,并根据字段的有效性管理打开工具提示。
如果您不打算使用工具提示,并且希望有一个良好的动态验证系统,可以扩展和自定义不同的错误,那么您可以做的比查看Angular的消息更糟糕:
https://scotch.io/tutorials/angularjs-form-validation-with-ngmessages
在这里:
http://blog.thoughtram.io/angularjs/2015/01/11/exploring-angular-1.3-validators-pipeline.html
https://stackoverflow.com/questions/35954372
复制相似问题