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

Comments

Projects
None yet
4 participants
@erikjung

erikjung commented Apr 17, 2014

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

This comment has been minimized.

Show comment
Hide comment
@matthewp

matthewp Apr 18, 2014

Contributor

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

Contributor

matthewp commented Apr 18, 2014

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

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Apr 25, 2014

Contributor
"" != null
Contributor

justinbmeyer commented Apr 25, 2014

"" != null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment