Search and Top Navigation
#10581 closed bug (notabug)
Opened September 01, 2014 11:47PM UTC
Closed September 02, 2014 12:46PM UTC
Last modified September 02, 2014 10:45PM UTC
autocomplete: item.value skips zero index
Reported by: | gadelat | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | none |
Component: | ui.autocomplete | Version: | 1.11.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I got something like this:
$('#form-name').autocomplete({ source: function(request, response) { $.ajax({ dataType: "json", url: "private_url", success: function(data) { response($.map(data, function(item, index) { return { label: 'test', value: index } })); } }) }, select: function(event, ui) { console.log(ui.item.value); } });
It worked fine in 1.10.4, but in 1.11.1 it outputs label instead of value when selecting first item. When selected other than first item, it works fine. I guess jquery-ui v. 1.11.1 puts label into value if index < 1
Attachments (0)
Change History (3)
Changed September 02, 2014 12:46PM UTC by comment:1
resolution: | → notabug |
---|---|
status: | new → closed |
Changed September 02, 2014 10:31PM UTC by comment:2
_comment0: | Uhh, can you enlighten me in decision to stop supporting numbers anymore? It's INDEX for gods sake, it's supposed to be zero and pass whatever check there is. Now user can't reliably do this anymore: \ \ var users = {}; \ $('#form-name').autocompleteExt({ \ source: function(request, response) { \ $.ajax({ \ dataType: "json", \ url: "private_url", \ success: function(data) { \ users = data; \ response($.map(data, function(item, index) { \ return { \ label: item.name, \ value: index \ } \ })); \ } \ }) \ }, \ select: function(event, ui) { \ event.preventDefault(); \ var user = users[ui.item.value]; \ $('#property1').val(user.property1); \ $('#property2').val(user.property2); \ $('#property3').val(user.property3); \ $('#property4').val(user.property4); \ } \ }); \ \ I can easily skip this check by doing String(index), but one should not be supposed to do that, indexes are not supposed to be strings just to pass illogical condition in library. → 1409697201523723 |
---|---|
_comment1: | Uhh, can you enlighten me in decision to stop supporting numbers anymore? It's INDEX for gods sake, it's supposed to be zero and pass whatever check there is. Now user can't reliably do this anymore: \ \ {{{ \ var users = {}; \ $('#form-name').autocompleteExt({ \ source: function(request, response) { \ $.ajax({ \ dataType: "json", \ url: "private_url", \ success: function(data) { \ users = data; \ response($.map(data, function(item, index) { \ return { \ label: item.name, \ value: index \ } \ })); \ } \ }) \ }, \ select: function(event, ui) { \ event.preventDefault(); \ var user = users[ui.item.value]; \ $('#property1').val(user.property1); \ $('#property2').val(user.property2); \ $('#property3').val(user.property3); \ $('#property4').val(user.property4); \ } \ }); \ }}} \ I can easily skip this check by doing String(index), but one should not be supposed to do that, indexes are not supposed to be strings just to pass illogical condition in library. → 1409697436911979 |
_comment2: | Uhh, can you enlighten me in decision to stop supporting numbers anymore? It's INDEX for gods sake, it's supposed to be zero and pass whatever check there is. Now user can't reliably do this anymore: \ \ {{{ \ var users = {}; \ $('#form-name').autocomplete({ \ source: function(request, response) { \ $.ajax({ \ dataType: "json", \ url: "private_url", \ success: function(data) { \ users = data; \ response($.map(data, function(item, index) { \ return { \ label: item.name, \ value: index \ } \ })); \ } \ }) \ }, \ select: function(event, ui) { \ event.preventDefault(); \ var user = users[ui.item.value]; \ $('#property1').val(user.property1); \ $('#property2').val(user.property2); \ $('#property3').val(user.property3); \ $('#property4').val(user.property4); \ } \ }); \ }}} \ I can easily skip this check by doing String(index), but one should not be supposed to do that, indexes are not supposed to be strings just to pass illogical condition in library. → 1409697844218375 |
Uhh, can you enlighten me in decision to stop supporting numbers anymore? It's INDEX for gods sake, it's supposed to be zero and pass whatever check there is. Now user can't reliably do this anymore:
var users = {}; $('#form-name').autocomplete({ source: function(request, response) { $.ajax({ dataType: "json", url: "private_url", success: function(data) { users = data; response($.map(data, function(item, index) { return { label: item.name, value: index } })); } }) }, select: function(event, ui) { event.preventDefault(); var user = users[ui.item.value]; $('#property1').val(user.property1); $('#property2').val(user.property2); $('#property3').val(user.property3); $('#property4').val(user.property4); } });
I can easily skip this check by doing String(index), but one should not be supposed to do that, indexes are not supposed to be strings just to pass this truth check in library.
Changed September 02, 2014 10:45PM UTC by comment:3
We didn't decide to stop supporting it. It was never supported in the first place, it just happened to work.
This isn't a bug, since autocomplete doesn't support numbers. The number
0
fails the truthy check ina || b
, the rest pass the test and are implicitly converted to strings.