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

When HTML attribute is empty, binders receives 0 instead of undefined #567

Closed
jccazeaux opened this issue Feb 4, 2016 · 4 comments
Closed

Comments

@jccazeaux
Copy link
Contributor

Issue

If binder is called like that

<div rv-my-binder></div>

Or

<div rv-my-binder=""></div>

It will receive 0 instead of null (or undefined ?)
See fiddle here : https://jsfiddle.net/jccazeaux/yqnubqkz/

Cause

The cause is in function parseType from parsers.coffee. In case of no HTML attribute we go into this case

else if (isNaN(Number(string)) === false) {
  value = Number(string)
}

because

     Number(null) == Number("") == 0

I think binder should receive undefined when HTML attribute is empty or not specified. If you agree i'll send the PR

@Duder-onomy
Copy link
Collaborator

👍 Agreed. We all know 0 will be coerced into a false but having it pass undefined is semantically correct.

My only issue, take the required attribute on the input tag for example. If the attribute is present, that is enough to warrant a true value. It does not have to be explicitly set as required='true'.
But..... That is weird anyways.

Thoughts?

@jccazeaux jccazeaux changed the title When HTML attribute is empty, binders receives 0 instead of null When HTML attribute is empty, binders receives 0 instead of undefined Feb 4, 2016
@jccazeaux
Copy link
Contributor Author

As you say it's weird, but it's still possible. The binder's code would have to consider undefined as true.

@Duder-onomy
Copy link
Collaborator

I am all for this. It is a minor but important improvement.

I will attach it to the 0.9 release. If anyone has any objections, please chime in.

@jccazeaux Will you champion this one for us?

@Duder-onomy
Copy link
Collaborator

Closing.

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

2 participants