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 comment:1
owner: | → johan-ludvigsson-stratsys |
---|---|
status: | new → pending |
Changed January 22, 2014 02:22PM UTC by comment:2
status: | pending → new |
---|
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 comment:3
status: | new → pending |
---|
Why are you sending a null
value?
Changed January 22, 2014 02:47PM UTC by comment:4
status: | pending → new |
---|
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 comment:5
status: | new → open |
---|---|
summary: | Normalize in jquery autocomplete is faulty → Autocomplete: 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 comment:6
resolution: | → fixed |
---|---|
status: | open → closed |
Autocomplete: Normalize falsy values, not just missing values
Fixes #9762
Changeset: 113e9d0c2cc3f474da719721857c074c983c7157
Changed January 22, 2014 03:41PM UTC by comment:7
milestone: | none → 1.11.0 |
---|
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/.