question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

eq evaluates always false

See original GitHub issue

I have this demo in Ember 2.4:

{{#each clients as |clientChoice|}}
{{clientId}} - {{clientChoice.id}}
{{eq clientId clientChoice.id}}
<br>
{{/each}}

And I get this evaluation in screen: 4 - 1 false 4 - 3 false 4 - 4 false 4 - 5 false

Why is this happening?

The complete code (I’m working with components): component.hbs:

<select class="form-control" onchange={{action "selectClient" value="target.value"}} id="selcl">
  <option value="" disabled selected>{{title}}</option>
  {{#each clients as |clientChoice|}}
    <option value={{clientChoice.id}} selected={{eq clientId clientChoice.id}}>{{clientChoice.firstName}} {{clientChoice.lastName}}</option>
  {{/each}}
</select>
{{clientId}}
{{#each clients as |clientChoice|}}
<br>
{{clientId}} - {{clientChoice.id}}
{{eq clientId clientChoice.id}}
{{/each}}

component.js

import Ember from 'ember';

export default Ember.Component.extend({
  clientId: Ember.computed('clientId', function() {
    return this.get('clientId');
  }),
  client: null,
  clients: Ember.computed('clients', function() {
    return this.get('clients');
  }),
  actions: {
    selectClient(clientId) {
      this.set('clientId', clientId);
      console.log($("select").val());
    }
  }
});

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
rwjbluecommented, Aug 19, 2016

@typeoneerror - Play around with http://jsbin.com/fidowu/edit?html,output. You will see that the selected attribute (what you see in the “Elements” pane in the Chrome DevTools) never updates even if you change which option is selected. This is (roughly) because the attribute is only used for initial render, and from then forward the property is used.

1reaction
krivatencommented, Sep 2, 2016

As to what @MichielDeMey mentioned, how I’ve handled this in the past was by creating a custom clone of the eq helper called aeq (Poor naming, but it’s short):

https://gist.github.com/krivaten/a7662fea8da50b42e5ff2311643103f3

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does "eq?" evaluate to false in the following context but ...
The expression 'expression is an abbreviation for (quote expression) . When the expression is evaluated it evaluates to expression as a data ...
Read more >
Eq with Poly object immediately evaulates to False #12873
And is_zero in Poly returns True if the poly is a zero-polynomial, and False if it's not, rather than returning whether it is...
Read more >
Why does Equal["string", False] not evaluate to False?
The answer seems to be something to do with strings being treated as symbols in some contexts but not others. For example, Solve...
Read more >
Why does condition always evaluate to false? - Jazz Forum
Trying to execute a conditional step - the condition always evaluates as false - why? A sample condition is 1 = 1 ,...
Read more >
Condition always evaluates to false - Power Platform Community
Solved: I'm playing with Flow and am trying to get a condition working but it always evaluates to false regardless/ I want the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found