Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Conditional required validation #165

Closed
yupswing opened this issue Sep 14, 2017 · 3 comments
Closed

Conditional required validation #165

yupswing opened this issue Sep 14, 2017 · 3 comments

Comments

@yupswing
Copy link

Hello @ghiscoding ,
I am trying to make a custom remote validator.

In a very particular case I have to make a field required based on a remote condition and if other fields are filled or not.
I made a custom remote validator but it does get triggered ONLY if there is some value in the field (not when it's empty).

Is there a way to make a conditional required validator?
I can't find anything in the wiki.

Thanks.

@ghiscoding
Copy link
Owner

Perhaps Wiki - Validate on Empty

@yupswing
Copy link
Author

yupswing commented Sep 14, 2017

yeah, thanks, that's exactly what I was looking for, but...

if I use required and I don't touch the form when I submit
new ValidationService().checkFormValidity()
it returns false.

but if I use validate-on-empty="true" it does pass validation successfully when field IS empty and my remote validator is just (in theory always failing)
return $q.when({isValid: false, message: 'test error'});

Maybe I did not understand, or validate-on-empty attr has a slightly different behaviour (on trigger matter) than required validator

(thanks for your answer, you are always very responsive and I honestly appreciate that a lot)

@ghiscoding
Copy link
Owner

ghiscoding commented Sep 14, 2017

I recently made a change #160 that might affect the usage of the validate-on-empty. The big problem that I have is that my E2E tests are broken since new versions of Chrome/Protractor and my last attempt to fix them was not really good. I don't have time to look into fixing the E2E.

If you could take a look at his Plunker (from #160) and try to reproduce your behavior in there, that might help to find the real issue.

Note: this project is just in life support mode as more people are going away from AngularJS 1.x (myself included). If you have time to find the bug and make a PR or point to where the issue is, that would greatly help. Thanks

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

No branches or pull requests

2 participants