表单验证不工作django-angular

时间:2015-01-28 12:20:01

标签: django angularjs forms validation django-forms

在表单

中使用前缀时,表单验证错误不会显示

当表单使用scope_prefix时,验证会中断。 错误消息停止显示,例如"字段需要"符。

以下示例:

 class ExampleForm(NgModelFormMixin, NgFormValidationMixin, forms.ModelForm):   
   form_name = 'example_form_name'
   controller = "ExampleFormController"

   def __init__(self, *args, **kwargs):
      kwargs.update(scope_prefix="formData")
      super(ExampleForm, self).__init__(*args, **kwargs)

html:

 <form name="{{ form.form_name}}" ng-controller="{{ form.controller}}" novalidate>
     {{ form }}
    <button type="submit" ng-disable="{{ form.form_name }}.$invalid"></button>
 </form>

html呈现为:

  <form name="example_form_name" class="ng-pristine ng-invalid ng-invalid-required" ng-controller="ExampleFormController" novalidate>

   <ul class="djng-form-errors ng-hide" ng-show="example_form_name.$dirty"></ul>
   <ul class="djng-form-errors" ng-show="example_form_name.$pristine">
     <li ng-show="example_form_name.$message" class="invalid ng-binding ng-hide" ng-bind="example_form_name.$message"></li>
   </ul>
   <ul class="djng-field-errors ng-hide" ng-show="example_form_name.textarea.$dirty">
   <li ng-show="example_form_name.textarea.$error.required" class="invalid">This field is required.</li>
   <li ng-show="example_form_name.textarea.$valid" class="valid ng-hide"></li>
   </ul>
   <ul class="djng-field-errors" ng-show="example_form_name.textarea.$pristine">
     <li ng-show="example_form_name.textarea.$message" class="invalid ng-binding ng-hide" ng-bind="example_form_name.textarea.$message"></li>
  </ul>
   <p>Label <textarea cols="40" name="textarea" ng-model="formData.textarea" ng-required="true" rows="10" class="ng-pristine ng-invalid ng-invalid-required" required="required"></textarea></p>
            <button class="submit" ng-disable="example_form_name.$invalid">Submit</button>
  </form>

控制器

controllers.ExampleFormController = function($scope) {
  $scope.formData = {};
  $scope.formSubmit = function() {
     // form submit actions
  }
}

但验证不起作用..如果我删除scope_prefix它工作正常。 我正在使用django-angular 0.7.0 我在这里缺少什么..

谢谢

1 个答案:

答案 0 :(得分:0)

禁用,而非禁用。

按钮应如下所示:

<button class="submit" ng-disabled="example_form_name.$invalid">Submit</button>