-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Model not updating when dynamic select element is manipulated via arrow keys #7042
Comments
I'm seeing change events when typing with focus on the select control, using Chrome 34.0.1847.116 (osx 10.9.2), which results in a model update. This may have been a browser bug. I don't see an issue about it, but the chromium issue tracker is a bit hard to sort through. In any case, at least in Chrome, this seems to be working now |
@caitp I'm seeing this problem also on Chrome Version 34.0.1847.116 Ubuntu 12.04 (260972) and Chrome Version 35.0.1916.153 m on Windows 7. When pressing the same key twice, the first key press gets synced to the model, but the second is ignored When looking at http://jsfiddle.net/ADukg/5116/
Try again using the 'A' key or the down arrow key instead of 'T' and you will see the same behavior on the second key press. Note 1: this only happens the first time you interact with the control after a page refresh |
Yeah that sounds like a chrome bug, hang on |
http://jsfiddle.net/mXg9n/ actually, this doesn't look like a chrome bug unless I'm reproducing this wrong (although occasionally it does stop responding to key events) |
I found something else interesting about the way this behaves. You can reproduce it by setting the select box back to a null value or other value not in the bound list, then follow the steps as before. It can be seen on https://docs.angularjs.org/api/ng/directive/select in the example at the bottom of the page.
For some reason the other select elements ("Null allowed" and "Grouped by shade") don't exhibit the same behavior. I've also noticed that it's not necessary to press the same key twice to trigger the behavior. You can click the first and down arrow the second to trigger it. However, the second selection must be made by keyboard (not mouse click) and it must be further down in the list than the first selection. I'm starting to suspect an issue with the way the select list is being managed internally rather than a missed event. |
This is also the same issue as #9134. |
I am experiencing the same problem as well in Chrome 41.0.2272.89 (64-bit) and Safari 8.0.4 (10600.4.10.7) on Max OS X. I had just created a Plunker and was about to submit a ticket when I saw this one. Here's my Plunker. http://plnkr.co/edit/Zsb3iiGeoc2Ep0OyaWek I was able to work around by adding an empty for now. |
Now I'm facing the same problem, I don't think it is a problem related to browser. Is there any way to tackle this problem? |
@vipin030, could you elaborate why you don't think it is a browser-related problem ? As explained elsewhere (and confirmed by @NateRedding), adding a explicit empty option solved the issue: <select ng-model="..." ng-options="...">
<option value="">--- Select (or any text you like) ---</option>
</select> |
@gkalpak , I have added the explicit option tag into my selection tag, but the problem is still exist, I have tested in firefox and chrome, it is not working in both. I have developed the same by using javascript for testing purpose, it is working fine on both the browser. Please check the below code for testing , it will work fine function getValue(obj){
console.log(obj.value);
}
|
@vipin030, can you provide the Angular code that is not working for you (or better yet provide a runnable demo, using CodePen, Plnkr, JSFiddle etc) ? |
@gkalpak , please check the below plnkr example, it is not working for me, The browser which I have tested is Firefox 37.0.1. Please let me know your thoughts. |
@vipin030, I tried your demo on latest Chrome and Firefox and it works as expected. Note that there is one difference between Chrome and Firefox in respect to when the select's value is changed:
The spec is somewhat unclear regarding that, stating that the value should be updated as soon as the user in done interacting with it, but it is a matter of interpretation. This might be a source of confusion sometimes. |
@gkalpak , Please check my demo code again You can see two selection box there, second one using our pure javascript to show the value, it is working on every browser regardless of the version Note: |
@vipin030, both versions work as expected (each 😃). If you want to update directive('changeOnKeyup', function changeOnKeyupDirective() {
return function changeOnKeyupPostLink(scope, elem) {
elem.on('keyup', elem.triggerHandler.bind(elem, 'change'));
};
}); |
Closing as dupe of #9134 |
Steps
What should happen?
at step 3, the model should be "TN"
at step 4, the model should change to "TX"
What happens and should not?
at step 4, the model stays to "TX"
Environment
Chrome 33 , angular 1.2 or beta 1.3
demonstration (taken from #2230):
http://jsfiddle.net/ADukg/5116/
or http://plnkr.co/edit/2R9YM6KF01bye4kPeoZL?p=preview
work around
<option value="" />
inside the select$(document).on( 'keyup', 'select', function(){$(this).trigger('change')} );
related
The text was updated successfully, but these errors were encountered: