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

can-value handling null in addition to undefined for select elements #891

Closed
erikjung opened this issue Apr 17, 2014 · 2 comments
Closed
Assignees
Milestone

Comments

@erikjung
Copy link

I have a use case where I need to have a default, empty value <option> within a <select> that uses can-value for live-binding.

<script id="tpl" type="text/mustache">
  <select can-value="theValue">
    <option value="">Choose</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
  </select>
</script>

The data passed to the template has null values by default on the properties that are bound to the <select>s.

can.$(document.body).append(
  can.view('tpl', {
    theValue: null
  })
);

It appears that can-live explicitly checks for undefined when determining whether or not to select an <option>

https://github.com/bitovi/canjs/blob/master/view/bindings/bindings.js#L182

It would be fantastic if this logic also accommodated null, which it currently does not due to typeof null evaluating as "object".

Code Pen example: http://codepen.io/erikjung/pen/Cvekz

@matthewp
Copy link
Contributor

The commit where the undefined check was added is fdd650c. I agree that we should be doing a == null check here instead.

@justinbmeyer
Copy link
Contributor

"" != null

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

No branches or pull requests

4 participants