0

I am facing an issue while selecting file using Angular.js. Here is my code:

<div ng-class="{'myError': billdata.compregdoc.$touched && billdata.compregdoc.$invalid }">
  <input type="file" 
         class="filestyle form-control" 
         data-size="lg" 
         name="compregdoc" 
         id="compregdoc" 
         ng-model="compregfile" 
         ngf-pattern="application/pdf,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
         accept="application/pdf,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.wordprocessingml.document" 
         ngf-select="onCompRegFileSelect($file);" 
         ngf-max-size="2MB">

  <div style="clear:both;"></div>
</div>
</div>
<div class="help-block" 
     ng-messages="billdata.compregdoc.$error" 
     ng-if="billdata.compregdoc.$touched">

  <p ng-message="pattern" style="color:#F00;">This field only accepts .pdf,.ppt,.docx files.</p>
  <p ng-message="maxSize" style="color:#F00;">File is too large.Max size is 2 mb.</p>
</div>

In this case I am only able to upload pdf type file. But here I need pdf,ppt,docx,excel format file upload. When I am selecting the docx file it is showing me the validation message that This field only accepts .pdf,.ppt,.docx files.

5
  • The file that you are selecting has a mime type that is none of the ones that you have specified in the ngf-pattern. Commented Feb 25, 2016 at 5:51
  • Alternatively you can use .pdf,.ppt,... format for ngf-pattern instead of the mime types which would only validate the file's extension. Commented Feb 25, 2016 at 5:52
  • @danial I am using version 7.0.15 and it does not filter by .ris files when i specify ngf-pattern=".ris". Am I doing something wrong? Commented Feb 29, 2016 at 14:45
  • @FernOfTheAndes create a jsfiddle. Commented Mar 4, 2016 at 23:53
  • @danial Sorry, I should have updated this...the following combo is what did it for me: ngf-pattern="'.ris'" and accept=".ris". Both were needed. Commented Mar 9, 2016 at 10:21

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.