#9762 closed bug (fixed)
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' }
Change History (7)
comment:1 Changed 8 years ago by
Owner: | set to johan-ludvigsson-stratsys |
---|---|
Status: | new → pending |
comment:2 Changed 8 years ago by
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".
comment:4 Changed 8 years ago by
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.
comment:5 Changed 8 years ago by
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.
comment:6 Changed 8 years ago by
Resolution: | → fixed |
---|---|
Status: | open → closed |
Autocomplete: Normalize falsy values, not just missing values
Fixes #9762
Changeset: 113e9d0c2cc3f474da719721857c074c983c7157
comment:7 Changed 8 years ago by
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/.