Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate only last files when ngf-keep="true #1007

Closed
derwu opened this issue Sep 15, 2015 · 13 comments
Closed

Validate only last files when ngf-keep="true #1007

derwu opened this issue Sep 15, 2015 · 13 comments
Labels

Comments

@derwu
Copy link

derwu commented Sep 15, 2015

When ngf-select ngf-keep="true" ngf-multiple="true" (and ngf-max-size="3MB" with upload on submit) and I add invalid file/files (maxSize exceeded in my case) files model is invalid (correctrly), but if next I add a valid file/files, then files model is valid (incorrectly). This seems to be incorrect, beceause in files model still is invalid file/files waiting to upload.

@derwu derwu changed the title Validate only lasts files when ngf-keep="true" Validate only last files when ngf-keep="true Sep 15, 2015
@derwu
Copy link
Author

derwu commented Sep 15, 2015

I updated ng-file-upload to recent version the problem seems to be fixed. Issue to close.

@derwu derwu closed this as completed Sep 15, 2015
@madurapa
Copy link

This issue is still exist as I'm using 12.0.1

@danialfarid
Copy link
Owner

When you set the ng-model value it will replace everything including the invalid files, so if you want it to persist the invalid files, add them to the ng-model variable before setting it.

@madurapa
Copy link

I'm sorry but I didn't get you. I added "ngf-keep" to keep the files I have been already chosen but when I add an invalid file it validates as should be but if I added a valid file again it doesn’t validate as it should be.

@madurapa
Copy link

I guess screenshots might help to understand the issue

  • In here I have selected valid and invalid files together and it validates correctly. step-1
  • Then again I have select a valid file and validation has been gone. step-2

@danialfarid danialfarid reopened this Feb 22, 2016
@madurapa
Copy link

Hi @danialfarid

There are couple of bugs I have found while testing. Will post them soon.

Thanks

@jar240
Copy link

jar240 commented Feb 23, 2016

"Me too". Assume I have:
<button ... ngf-max-files="5" ngf-keep="distinct" (or true) ...>

...if I try to select 6 files, the validation kicks in and works. The issue is, when I click the button again to reselect 5 or less files, the validation hasn't been cleared -- still invalid.

If I set ngf-keep="false", everything works as expected; the problem is, this behaviour is undesirable in my case.

(Version 12.0.1)

Chris

@danialfarid
Copy link
Owner

@jar240 you need to reset the ng-model to empty if you want to remove those files. Removing them from ngf-invalid-model will not trigger any validation, you need to set the ng-model to empty array or whatever files are left there.

@jar240
Copy link

jar240 commented Feb 24, 2016

@danialfarid an example would be stellar. The timing isn't clear to me... In my mind, this should be taken care of by ng-file-upload when the upload button is clicked a second (third, fourth, etc. time).

Otherwise how would I implement this in a sensible way?

Thanks,
Chris

@madurapa
Copy link

@danialfarid is it possible to handle all valid and invalid files in a single model with a flag invalid then maybe set what is/are the reason(s) for invalid with another or in the same object. Like invalid extension, max file size, or max file count, etc. I think it would be better to attached error with each file object and as a global error array too. Then we can handle everything at one place.

We could also implement remove method inside the directive so then it will be easy to change valid/invalid states in the model.

@danialfarid
Copy link
Owner

@madurapa It is already attached to each file, just set ng-model-options="{allowInvalid: true}" to get all files with their error reason etc. '$errorand$errorParam` it is mentioned in the docs.
@jar240 you can also use this approach. If you have this option set and update the model the validations will be revalidated.

@madurapa
Copy link

madurapa commented Mar 9, 2016

I've missed that option, It makes life easier ;)

@danialfarid
Copy link
Owner

fixed at version 12.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants