[英]ng-file-upload validation does not run (form always valid)
我需要为数组中的每个项目上传文件。 我正在使用ng-repeat
遍历数组和ng-file-upload插件来处理文件上传和验证。 预期结果将是多种形式。 每次ng-repeat
但是出于某种原因,验证永远不会失败,并且总是提交表单。
查看代码(为清楚起见已简化):
<div ng-repeat="point in endpoints">
<div class="panel-body" >
<form name="uploadForm">
<div class="media-uploader button drop-box"
ng-model="file"
name="file"
ngf-drag-over-class="'dragover'"
ngf-accept="{{point.endpoint.type.acceptedFormat.join('/*,') }}/*"
ngf-select="uploadForm.$valid && submitUpload($file, point)"
ngf-drop="submitUpload($file, point)"
ngf-max-size="{{ maxFileUploadSize }}"
ngf-pattern="{{ point.endpoint.type.acceptedFormat.join('/*,') }}/*"
ngf-max-duration="{{ (point.timeslots * 15)+tolerance }}"
ngf-validate = "{width: {min: {{ point.endpoint.format.width }}, max:{{ point.endpoint.format.width }}},
height: {min: {{ point.endpoint.format.height }}, max: {{ point.endpoint.format.height }}}
}">
<p>Click or drag to select images and video</p>
</div>
</form>
<div class="has-error" >
<div ng-show="uploadForm.file.$error.maxHeight || uploadForm.file.$error.maxWidth ">
Media must be {{ point.endpoint.format.width }} × {{ point.endpoint.format.height }}px
</div>
<div ng-show="uploadForm.file.$error.maxSize">
Max upload size exceeded the maximum allowed size is 200MB
</div>
<div ng-show="uploadForm.file.$error.pattern ">
This endpoint only allows {{ point.endpoint.type.acceptedFormat.join(', ') }} uploads
</div>
<div ng-show="uploadForm.file.$error.maxDuration ">
Your video exceeds the maximum allowed time of {{ point.timeslots * 15 }} seconds.
</div>
</div>
</div>
我怀疑这与ng-repeat
的uploadForm
范围有关,但是如果我对ng-repeat
理解是正确的,则每次迭代都应具有自己的范围。
我想念什么?
您可以使用ng-form
创建动态表单并对其进行验证
<form name="outerForm">
<div ng-repeat="item in items">
<ng-form name="innerForm">
<input type="text" name="foo" ng-model="item.foo" />
<span ng-show="innerForm.foo.$error.required">required</span>
</ng-form>
</div>
<input type="submit" ng-disabled="outerForm.$invalid" />
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.