0

I have an issue while trying to implement ng-file-upload of Angular.js and my problem is i am not getting any validation message while uploading wrong file.My explaining my code below.

<form name="billdata" id="billdata"  enctype="multipart/form-data" novalidate>
   <div class="input-group bmargindiv1 col-md-12" ng-show="status==1">
        <div ng-class="{ 'myError': billdata.bannerimage.$touched && billdata.bannerimage.$invalid }">
        <div class="image-upload text-center">
        <label for="imagefile1">
        <img ng-src="{{attchImage1}}" style="cursor:pointer;width:auto; height:160px; border:1px #666 solid"/>
        </label>
<input type="file"  data-size="lg" name="bannerimage" id="imagefile1"  ng-model="file" ngf-pattern="image/*" accept="image/*" ngf-max-size="2MB" ngf-min-height="100" ngf-resize="{width:100, height:100}"   custom-on-change="uploadFile"  ngf-select="onFileSelect($file);" >
<div class="input-group bmargindiv1 col-md-12">
        <label for="imagefile1" >
        <span style="color:#00F; font-style:italic; cursor:pointer"> Click here to upload Image </span>
    <input type="hidden" name="someData" ng-model="imageData" />
      </label>
</div>

 </div>
 </div>

</div>
 <div class="help-block" ng-messages="billdata.bannerimage.$error" ng-if="billdata.bannerimage.$touched">
<p ng-message="maxSize" style="color:#F00;">File is too large.Max size is 2 mb.</p>
<p ng-message="minHeight" style="color:#F00;">Minimum height should be 100px</p>
</div>

</form>

Here when i am uploading the wrong file size(i.e-min-height<100px) the validation error message should display but its not coming at all.Please help me to resolve this issue.

10
  • Can we have a Fiddle of the same ? Commented Mar 5, 2016 at 4:17
  • do you have angular-messages.js loaded? Commented Mar 5, 2016 at 4:19
  • @Bonatoc : Yes, I have ` <script src="js/angular-messages.js" type="text/javascript"></script>`. Commented Mar 5, 2016 at 4:22
  • what does console.log(billdata. bannerimage.$error) says ? Commented Mar 5, 2016 at 4:32
  • "When any of the validation directives specified the form validation will take place and you can access the value of the validation using myForm.myFileInputName.$error.<validate error name> for example form.file.$error.pattern. If multiple file selection is allowed you can specify ngf-model-invalid="invalidFiles" to assing the invalid files to a model and find the error of each individual file with file.$error and description of it with file.$errorParam. You can use angular ng-model-options to allow invalid files to be set to the ng-model ng-model-options="{allowInvalid: true}". Commented Mar 5, 2016 at 4:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.