-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
required & ng-model #1052
Comments
Could you create a jsfiddle? |
It's too complicated to create a JSFiddle for what I am experiencing. in controller: I define scope.picFile = "someUrl" in html: I notice this: if the <input is outside the loop: scope.picFile retains value I don't expect you to be able to find the problem by what I gave you. But if it's obvious enough or something you suspect maybe the problem, I would appreciate your help. Thank you, Tan |
The question is how do you set the initial value of the model that is bind to the file input ngf-select? You need to first select a file so you could have a file to be assigned to the model. |
As I mentioned in previous post, I set scope.picFile to 'someUrl'. Then I bind the input by ng-model = 'picFile'. It works fine (I can see the image). Only when I put the ngf-select in my loop, somehow the scope.picFile is set to null or undefined. I tested by making one ngf-select outside the loop, one inside but both bind to the same scope.picFile. the one outside the loop still has the image but the one inside lost it. It made me wonder the one inside the loop might have pointed to something else. But I know I did not touch scope.picFile anywhere other than ng-model inside the two ngf-select.. I can put the project in a zip file and share on Google drive. Thank you Tan |
url is not a file, so setting the input file model to a url doesn't make sense much. In order to see it in ngf-src or ngf-thumbnail you can do ngf-thumbnail="picFile || someUrl" so it would initially so the url and once you select the file it would show the file. |
Hello, I understand that I might need to download the file to base64 ? Thank you. |
@FunnyBones |
What would be the best way to create an initial value programmatically for the model that is accepted as valid? I had this structure in previous versions of ng-file-upload, and it worked well:
How can I create sth like this that will be accepted as a valid file in version 12? |
@pbouda it needs to be of type File or Blob so use File constructor |
input name="myInput" type="file" ngf-select
ng-model="form.value" name="file"
accept="image/*" ngf-max-size="2MB" required>{{myInput.$valid}}"
myInput.$valid is false even though the form.value (existing image) is a valid image. myInput.$valid only turn to true if I upload a new image.
Basically, I want the file upload is only required if there is no existing image.
Thanks,
Tan
The text was updated successfully, but these errors were encountered: