Skip to content

Commit

Permalink
Fix primefaces#6633: AutoComplete with selectedItemTemplate (primefac…
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Oct 17, 2024
1 parent 96dd0d1 commit 5cc4a5e
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions components/lib/autocomplete/AutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,20 @@ export const AutoComplete = React.memo(
selectedItem.current = ObjectUtils.isNotEmpty(value) ? value : null;
};

const formatValue = (value) => {
if (ObjectUtils.isNotEmpty(value)) {
if (typeof value === 'string') {
return value;
} else if (props.selectedItemTemplate) {
const resolvedFieldData = ObjectUtils.getJSXElement(props.selectedItemTemplate, value);

return resolvedFieldData ? resolvedFieldData : value;
} else if (props.field) {
const resolvedFieldData = ObjectUtils.resolveFieldData(value, props.field);

return resolvedFieldData !== null && resolvedFieldData !== undefined ? resolvedFieldData : value;
}
const formatValue = (value, useTemplate = false) => {
if (ObjectUtils.isEmpty(value)) return '';

if (typeof value === 'string') return value;

if (useTemplate && props.selectedItemTemplate) {
return ObjectUtils.getJSXElement(props.selectedItemTemplate, value) || value;
}

return value;
if (props.field) {
return ObjectUtils.resolveFieldData(value, props.field) ?? value;
}

return '';
return value;
};

const updateInputField = (value) => {
Expand Down Expand Up @@ -608,7 +604,7 @@ export const AutoComplete = React.memo(

return (
<li key={key} {...tokenProps}>
<span {...tokenLabelProps}>{formatValue(val)}</span>
<span {...tokenLabelProps}>{formatValue(val, true)}</span>
{removeTokenIcon}
</li>
);
Expand Down

0 comments on commit 5cc4a5e

Please sign in to comment.