Jquery Autocomplete Normalize data issue
Hi
I am using jquery UI autocomplete in my application. I am populating items which are objects with label and value. A value field contains the id of the label item.
The issue which I am facing is when the id is 0. In this case, the value field will get replaced by text data present in the label field. This is happening in the "Normalize" method in Jquery UI file.
How can I override the Normalize method? Please check the code below. The issue occurs in code highlighted in red.
_normalize: function( items ) {
// assume all items have the right format when the first item is complete
if ( items.length && items[ 0 ].label && items[ 0 ].value ) {
return items;
}
return $.map( items, function( item ) {
if ( typeof item === "string" ) {
return {
label: item,
value: item
};
}
return $.extend( {}, item, {
label: item.label || item.value,
value: item.value || item.label $.extend( {}, item, {
label: item.label || item.value,
value: item.value || item.label
} );
} );
}