角度自定义验证消息未显示

时间:2016-05-25 12:41:20

标签: angularjs validation custom-error-handling

我在AngularJS应用中验证时显示自定义消息时遇到问题。

以下是我的代码:

<div class="row">
    <div class="input-field col s12">
       <input id="description" rows="3" class="materialize-textarea no-pad-bot no-pad-top" ng-model="Description" ng-required="isValidationRequired()" ng-minlength="5"></input>
        <span class="help-inline" ng-show="submitted && frm1.description.$error.required">Comments are required</span>

     </div>
 </div>

 <input type="submit" class="white-text waves-effect btn" value="Enter" ng-click="submitted=true" />

以上工作但显示的信息是“请填写此字段”。这不是我指定的消息。我希望显示自己的自定义消息。我发现我的代码没有任何问题。任何人都可以帮助我指出正确的方向。

2 个答案:

答案 0 :(得分:1)

您的代码存在一些问题。

  1. 表格不包括在内,我假设你刚才在这篇文章中没有包含那段代码。

  2. 您需要指定输入的名称。 所以在做frm1.description时,它知道什么是描述。

  3. 确保函数isValidationRequired返回true

  4. 您需要在表单标记

  5. 中包含novalidate

    在这里,我有一个工作示例

      <form novalidate name="frm1">
    <div class="row">
    <div class="input-field col s12">
       <input name="description" id="description" rows="3" class="materialize-textarea no-pad-bot no-pad-top" ng-model="Description" ng-required="isValidationRequired()" ng-minlength="5"></input>
        <div class="help-inline" ng-show="submitted && frm1.description.$error.required">Comments are required</div>
    
     </div>
    

      

    http://jsfiddle.net/mlhuff12/Lvc0u55v/4503/

答案 1 :(得分:0)

你收到一条消息,你做了代码吗?听起来像浏览器验证。检查您的对帐单并添加“novalidate”。即。

<form novalidate>

也许这有帮助...