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.

sometime select's event does't work when option's vlaue in ('',0)

See original GitHub issue

Vue.js version

2.1.6

Reproduction Link

http://sandbox.runjs.cn/show/xu7gfzz2

Steps to reproduce

switch tag option between value=‘’ and value=‘0’, then to see {{ selected }}'s change.

What is Expected?

the value of ‘selected’ always changes with your choose.

What is actually happening?

sometime works, sometime does’t work.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
defcccommented, Dec 20, 2016

Campares fails in looseEqual, I’ll make a patch.

0reactions
rpkilbycommented, Dec 19, 2016

@LinusBorg testing on chrome 56/OS X, I can verify that the fiddle is broken (whether or not it’s Vue or the fiddle’s fault, not sure).

  1. The select is initialized with “on” and the text displays “Selected: 1”.
  2. Select “off”.
    • Expected the selected option to be “off”, text should display “Selected: 0”.
    • Selected option was the empty choice, text correctly displays “Selected: 0”.
  3. Select “off” again (since it’s currently empty).
    • The “off” option is correctly selected, text correctly displays “Selected: 0”.
  4. Select the empty choice.
    • The empty choice is correctly selected, text correctly displays "Selected: ".
  5. Select “off”. Even though the current choice is empty, this breaks again.
    • Expected the selected option to be “off”, text should display “Selected: 0”.
    • Selected option was the empty choice, text correctly displays “Selected: 0”.
  6. Select “off” again (since it’s currently empty).
    • The “off” option is correctly selected, text correctly displays “Selected: 0”.

I was able to fix the fiddle in two ways:

  • change the numeric values to strings.
  • change the ‘empty’ option to a number (such as -1).

Either vue is getting confused by having two falsey values (‘’, 0), or vue is getting confused by the mixed types.

Read more comments on GitHub >

github_iconTop Results From Across the Web

click event on select option element doesn't work [closed]
It works because the "select" elements takes the value from its selected "option". Edit 2. Simplified again by changing $(this).val() into e.
Read more >
First option in select dropdown appears selected when no ...
When a select dropdown value is bound to a component variable, and this variable doesn't match any of the options in the dropdown, ......
Read more >
Select not working - options not appearing on click
Hi, I am having trouble with the material select in my application. The element looks as if it is initializing as expected, however...
Read more >
SCR19: Using an onchange event on a select element ... - W3C
Navigate to the trigger select element, navigate through the options but do not change the value. Check that the matching option values are...
Read more >
Selecting Elements - jQuery Learning Center
This won't work. When a selection is made using $() , an object is always returned, and objects always evaluate to true ....
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