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

ng-required is not working with ng-if #1144

Closed
bogdanalexe90 opened this issue Nov 18, 2015 · 6 comments
Closed

ng-required is not working with ng-if #1144

bogdanalexe90 opened this issue Nov 18, 2015 · 6 comments

Comments

@bogdanalexe90
Copy link

Hi,
If i use the component with ng-required inside an ng-if when ng-if changes the model is not valid anymore. Take the following use case:

  1. ng-if = true
  2. select a file (required is valid)
  3. ng-if = false
  4. ng-if = true
    5 required is invalid, if i change the file it becomes valid again.
@bogdanalexe90
Copy link
Author

May be related to this one #1052

In my case the initial value is a valid File object. Because ng-if will destroy the directive but not the model. When the directive is re-created some how model is interpreted as invalid.

@bogdanalexe90
Copy link
Author

After a bit of investigation i noticed that this will never work because a big part of the validation logic it was designed around that input[file] and there is no way to do 2way binding with it. Do you plan in the feature to refactor this around ngModel and to not stay tied to the native validation?

@danialfarid
Copy link
Owner

input file is kind of different from other inputs in the way that you cannot set a value for it programmatically, so there is no two way binding you can just set it to null.
I will have a look into it for the next release to see if it make sense to have the validation run on the model but not on the actual element's value.

@danialfarid
Copy link
Owner

Actually it is already tied to the model only. I am guessing when you have ng-if it would reset the model values that are bind to the newly compiled elements. If you could create a jsfiddle showing the issue I will investigate more.

@wickY26
Copy link

wickY26 commented Sep 23, 2016

Hello, I design an editor where user needs to select a contentType from editor menu and each menu tab has its own validation rules depends on their content types.

So, some content types has file selector where I use your directive and its validations for it but when user select a content type and make it valid then move to another content type and turn back again valid nested form become invalid because of ng-if.

I reproduced the error from your demos at home page. Here is the link for it http://jsfiddle.net/0rgm4az4/

For who looking for temporary solution you could use ng-show but then you need to put ng-show condition with ng-required for dynamic validation for invisible areas...

@danialfarid could you reopen this issue please?

danialfarid added a commit that referenced this issue Sep 23, 2016
@danialfarid
Copy link
Owner

Fixed at 12.2.11

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

No branches or pull requests

3 participants