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

Field level validate on empty not working #160

Closed
mandarranade opened this issue Jul 3, 2017 · 8 comments
Closed

Field level validate on empty not working #160

mandarranade opened this issue Jul 3, 2017 · 8 comments

Comments

@mandarranade
Copy link

as per
https://github.com/ghiscoding/angular-validation/wiki/Inputs-(local-options)#validate-on-empty
we should be able to set validate on empty via code for a particular field. Unfortunately this option is not working. I'm afraid the issue is happening in the ValidationService inside addValidator function. From my analysis I feel problem is at
https://github.com/ghiscoding/angular-validation/blob/master/src/validation-service.js#L101 . we should be accessing attributes from attrs instead of self.validationAttrs . If attrs are not available then we should try to access self.validationsAttrs . (if element level validations not specified try getting value from global level validationsAttrs )
Can you please look into the same?

@mandarranade mandarranade changed the title Field level attributes by passed for validate on empty Field level validate on empty not working Jul 3, 2017
@ghiscoding
Copy link
Owner

Hello, if you think that you can change the code to fix the issue, I certainly welcome PR (pull request)

@mandarranade
Copy link
Author

mandarranade commented Jul 5, 2017

I will try.. let you know asap. Thanks for prompt reply as usual 👍

@ghiscoding
Copy link
Owner

Looking at this opened ticket and reviewing what you wrote. You might have misunderstood what this does. This is meant for doing a validation even if the field is empty and doesn't have a "required" validation.

You haven't provided any code (I prefer a Plunker to work with), so it's hard to help you out.

@mandarranade
Copy link
Author

Sorry for late reply was busy. All I was trying to tell was if we try to use field level attributes to validate to check if field is empty or not (as a service not directive) then line number 101 fails. From my analysis it should be
_validateOnEmpty = (attrs.hasOwnProperty('validateOnEmpty')) ? self.commonObj.parseBool(attrs.validateOnEmpty) : ((self.validationAttrs.hasOwnProperty('validateOnEmpty')) ? self.commonObj.parseBool(self.validationAttrs.validateOnEmpty) : !!_globalOptions.validateOnEmpty);

Instead of current
_validateOnEmpty = (self.validationAttrs.hasOwnProperty('validateOnEmpty')) ? self.commonObj.parseBool(self.validationAttrs.validateOnEmpty) : !!_globalOptions.validateOnEmpty;

Current logic takes Global property not the field level property.

Thanks. I'm sorry I don't have plunkr available. I will try to make one.

@ghiscoding
Copy link
Owner

ghiscoding commented Aug 31, 2017

Have you tested it in your environment? You can use the unbundled version of Angular-Validation and modify the validation-service.js file

@mandarranade
Copy link
Author

Okay. So I finally created a plukr here
It has all required files and 2 versions of your JS file.
ghiscodingwithfix has the fix. Please try changing references in index.html. If you notice I just have custom validator and validate on empty true. With the current file in your repo it returns form is valid although it's not.
Thanks.

@ghiscoding
Copy link
Owner

I pushed a fix with some of your recommendations, please use the new version 1.5.24, thanks

@mandarranade
Copy link
Author

Awesome. Thanks a lot. :)

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