角形无法验证

时间:2016-02-12 12:10:02

标签: javascript angularjs validation

我有以下表格:

<form name="ff" ng-submit="formSubmit(ff)" role="form" class="form-horizontal" id="form-{{context.identifier}}" novalidate>
    <div class="col-xs-12 box-shadow">
      <div class="col-xs-6" style="margin-top: 1em;">
        <input type='hidden' name='nodeIdentifier' value='{{context.currentStep.identifier}}' />
        <input type='hidden' name='contextIdentifier' value='{{context.identifier}}' />
        <div class="form-group">
          <label class="control-label col-xs-4" for="requestor_name">Approve:</label>
          <div class="col-xs-8">
            <select name="form.field.decision">
              <option value="Approved">Approved</option>
              <option value="Denied">Denied</option>
            </select>
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-xs-4" for="form.field.reason">
            Reason:</label>
          <div class="col-xs-8">
            <input class="form-control" type="text" name="reason" required minlength='4' maxlength='255'/>
          </div>
          <div ng-messages="ff.reason.$error" role="alert">
            <div ng-message="required">You did not enter a reason</div>
            <div ng-message="minlength, maxlength">
              Your reason must be between 4 and 255 characters long
            </div>
          </div>
        </div>
        <div class="form-group">
          <input type="submit" name="submit" value="submit" />
        </div>
      </div>
    </div>
  </form>

以下是记录formSubmit(data)中提交内容的代码:

console.log("Data");
console.log(data);

我的表单始终显示有效。为什么角度验证不起作用?我也包括了nagular消息。

1 个答案:

答案 0 :(得分:0)

您没有绑定到输入字段的ng-model。看起来ngMessages需要那些。

编辑:发现对教程的评论,因为我不是100%肯定:

  

不包括验证字段中的ng-model属性的fyi   打破表单验证