Skip to main content

Search and Top Navigation

#9762 closed bug (fixed)

Opened January 22, 2014 10:14AM UTC

Closed January 22, 2014 03:40PM UTC

Last modified January 22, 2014 03:41PM UTC

Autocomplete: Normalization should handle null values

Reported by: johan-ludvigsson-stratsys Owned by: johan-ludvigsson-stratsys
Priority: minor Milestone: 1.11.0
Component: ui.autocomplete Version: 1.8.17
Keywords: Cc:
Blocked by: Blocking:
Description

In the _normalize function the following is returned:

return $.extend({
    label: item.label || item.value,
    value: item.value || item.label
}, item );

Which means if that if the properties label and value are present in item, they will overwrite the values regardless if they are undefined or not.

This could be fixed by reversing the order and use an empty object as target:

return $.extend({}, item, {
    label: item.label || item.value,
    value: item.value || item.label
});

So if the item is:

{ 
  label: 'Hello',
  value: null
}

it will be normalized correctly to:

{ 
  label: 'Hello',
  value: 'Hello'
}
Attachments (0)
Change History (7)

Changed January 22, 2014 01:54PM UTC by tj.vantoll comment:1

owner: → johan-ludvigsson-stratsys
status: newpending

Hi johan-ludvigsson-stratsys,

Thanks for taking the time to contribute to jQuery UI.

Could you give an example showing this behavior in action? I'm confused how users of the widget would run into this. You can use this test case as a starting point: http://jsfiddle.net/tj_vantoll/hmarM/.

Changed January 22, 2014 02:22PM UTC by johan-ludvigsson-stratsys comment:2

status: pendingnew

I modified it to give an example: http://jsfiddle.net/hmarM/19/

We mostly ran into this today when we were sending out JSON-objects to populate the suggest list. The main difference you will see, is what happens when you search and select "Hello" compared to "Jquery". In the first case, the input is cleared, while in the second case the input value is changed to "JQuery".

Changed January 22, 2014 02:44PM UTC by scottgonzalez comment:3

status: newpending

Why are you sending a null value?

Changed January 22, 2014 02:47PM UTC by johan-ludvigsson-stratsys comment:4

status: pendingnew

It is being serialized from an object on server side, where we may or may not depending on events set a specific value for an item.

Changed January 22, 2014 03:01PM UTC by scottgonzalez comment:5

status: newopen
summary: Normalize in jquery autocomplete is faultyAutocomplete: Normalization should handle null values

This wasn't the intention of the normalization, but I don't see any harm in supporting this.

Changed January 22, 2014 03:40PM UTC by Scott González comment:6

resolution: → fixed
status: openclosed

Autocomplete: Normalize falsy values, not just missing values

Fixes #9762

Changeset: 113e9d0c2cc3f474da719721857c074c983c7157

Changed January 22, 2014 03:41PM UTC by scottgonzalez comment:7

milestone: none1.11.0