1

i'm using Angular's JS well known ng file upload directive (https://github.com/danialfarid/ng-file-upload) in a project i'm working on, but i'm having an issues regarding validations. I added the ngf-pattern directive, in order to prevent users from uploading certain file formats. This works well, and each invalid file is available in the $invalidFiles array. Is there anyway to clear this array?

I am using $invalidFiles array in order to detect when invalid file was used, and alert the user. The file is not displayed in the UI, and not added to my model, but still I cannot submit the form because the form is invalid. only after I add a valid file I can submit the form. Is there a way to detect invalid files but still be able to submit the form ?

Hope I was clear.. Thanks!

7
  • can we have a Fiddle for your scenario ? Commented Apr 26, 2016 at 20:20
  • yes! you can find it here: jsfiddle.net/2vq88rfs/631 . if you add invalid file it won't be added to the model, it will be added to the error files array and the form will be invalid until a valid file will be added. I just want to be able to catch the error, but still submit the form (if before some valid files were already added). hope it helps.. Commented Apr 26, 2016 at 21:03
  • 1
    @tsahnar if you want to submit an invalid form then what is the point of knowing if the form is valid or not? Commented Apr 26, 2016 at 23:04
  • @Akis_Tfs Have you selected proper user for your comment ? Commented Apr 26, 2016 at 23:09
  • 1
    @Sampath i am really sorry, wrong tag Commented Apr 26, 2016 at 23:10

2 Answers 2

1

Is this what you need : JsFiddle

$scope.submit = function() {
    alert('form is ready');
   }
Sign up to request clarification or add additional context in comments.

2 Comments

now you removed the condition that checks if the form is valid or not., so it misses the whole point
You can still catch the errors and also form can be submitted no ? If not what do you need ?
0

Probably the thing you really need is ngf-change rather then ngf-select. Based on the documentation, the handler function you assign to ngf-change directive would be called whenever you select, drop, or cleared.

If the only thing you want to achieve is to allow form submission regardless it's valid or invalid, another approach would be leveraged on ng-model-options. There is an option called allowInvalid, by default it's false, set it to true would do the trick.

So in your example:

<button name="bla" multiple accept="image/*"              
        ngf-keep="true" 
        ng-model="myFiles" 
        ngf-pattern="'image/*'" 
        ngf-max-size="1MB"
        ngf-change="handleFiles($files, $invalidFiles)"
        ngf-model-options="{allowInvalid: true}">
  Select Files
</button>

Notice the last two directives we have changed here.

For full reference, you may check the official document at the section of Full reference - File select and drop

1 Comment

@tsahnar no worry, feel free to vote it up if it works for you.

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.