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

hasValue returns 'true' for an empty object #317

Open
majuric opened this issue Oct 30, 2015 · 1 comment
Open

hasValue returns 'true' for an empty object #317

majuric opened this issue Oct 30, 2015 · 1 comment
Labels

Comments

@majuric
Copy link

majuric commented Oct 30, 2015

hasValue() returns an info whether data being validated has any value .. basically it checks whether data is empty. This works fine for everything except for object, for which hasValue returns true even if it's empty ..

https://github.com/thedersen/backbone.validation/blob/master/src/backbone-validation.js#L568

hasValue( '' ) // false
hasValue( [] ) // false
hasValue( null ) // false
hasValue ( undefined ) // false

hasValue( {} ) // TRUE

I'm not sure if this is by design, but I would expect that empty object be treated as having no value.

Also, I believe underscores '_.isEmpty' would cover all of the cases since it's pretty consistent in what it considers 'empty'

_.isEmpty('') // true
_.isEmpty({}) // true
_.isEmpty(undefined) //true
_.isEmpty(null) // true
_.isEmpty('') // true

so in stead of hasValue(value), !_.isEmpty(value) could be used ?

@chiefGui chiefGui added the bug label Nov 23, 2015
@chiefGui
Copy link
Collaborator

You are totally right! Working on it!

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

2 participants