简体   繁体   English

ng-file-upload验证(ngf- [max | min]-[height | width]或ngf尺寸)似乎没有生效

[英]ng-file-upload validation (ngf-[max|min]-[height|width] or ngf-dimensions) not appearing to take effect

Some of the ng-file-upload directives are clearly working here: I can see the image preview, and upload works well. 某些ng-file-upload指令在这里显然可以正常工作:我可以看到图像预览,并且上传效果很好。 I am now attempting to validate the image resolution. 我现在正在尝试验证图像分辨率。 I see the following below when inspecting the element: 检查元素时,我在下面看到以下内容:

<input type="file" ngf-dimensions="$width == 114 && $height == 114" ng-select="onFileSelect($files)" accept="image/png" base-sixty-four-input="" ng-model="fileDesc.file" name="filename_png" id="filename_png" class="ng-untouched ng-valid ng-isolate-scope ng-valid-parse ng-dirty">

I can see that the ngf-dimensions attribute is getting populated correctly, and additionally, ng-dirty is getting set because I've attempted to upload a file at this point. 我可以看到ngf-dimensions属性已正确填充,此外,还设置了ng-dirty ,因为此时我已尝试上传文件。 But the file's dimensions are not 114x114. 但是文件的尺寸不是114x114。 Shouldn't I be seeing ng-invalid instead of ng-valid ? 我不应该看到的ng-invalid的,而不是ng-valid

I've also tried this longer phrasing, which I believe to be equivalent, with the same effect: 我还尝试了更长的措辞,我认为这是等效的,具有相同的效果:

<input type="file" ngf-min-width="114" ngf-min-width="114" ngf-min-height="114" ngf-max-height="114" ... >

Is there something specific that needs to be done in order to enable the validation of form fields and the ability to check form.field.$error ? 为了启用表单域的验证和检查form.field.$error的能力,是否需要执行一些特定的操作?

Updated to add ng-file-upload version: 11.2.0 更新以添加ng-file-upload版本:11.2.0

Edited again to add the output of Test: {{form.field}} , should $validators be populated? 再次进行编辑以添加Test: {{form.field}}的输出,是否应该填充$validators Or perhaps I'm having some conflict by using the base64 upload directive as well here? 还是我在这里也使用base64 upload指令遇到了一些冲突?

Test: {"$viewValue":{"filetype":"image/png","filename":"PNG successful.png","filesize":383443,"base64":"..."},"$validators":{},"$asyncValidators":{},"$parsers":[null,null,null,null],"$formatters":[],"$viewChangeListeners":[],"$untouched":true,"$touched":false,"$pristine":false,"$dirty":true,"$valid":true,"$invalid":false,"$error":{},"$name":"filename_png","$options":null}

I'm not familiar with the library, but it looks like its reference docs say: 我不熟悉该库,但是它的参考文档看起来像这样:

 ngf-dimensions="$width > 1000 || $height > 1000" or "validateDimension($file, $width, $height)"
 // validate the image dimensions, validate error name: dimensions

If I look at the author's validation example below, he appears to be using the required attribute, which may be your only issue, but I would also check form.file.$error.dimensions to see if the error is being caught at all: 如果我看下面作者的验证示例,他似乎正在使用required属性,这可能是您唯一的问题,但我还将检查form.file.$error.dimensions以查看是否完全捕获了错误:

<input type="file" ngf-select ng-model="picFile" name="file" accept="image/*" ngf-max-size="2MB" required ngf-model-invalid="errorFiles">

I should have provided a jsfiddle in the first place. 我应该首先提供一个jsfiddle。 Was just trying to generate one to reproduce my issue, and it forced me to realize that my code had lost the ngFileUpload injection on the module. 只是试图生成一个来重现我的问题,这迫使我意识到我的代码丢失了模块上的ngFileUpload注入。 No wonder it wasn't working. 难怪它没有用。 Thanks, @danial, for the nice work. 谢谢@danial的出色工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM