Skip to content

Commit

Permalink
Improved: Add display result format for auto-completion on lookup (OF…
Browse files Browse the repository at this point in the history
…BIZ-13173) (#853)

Currently, when you have a lookup with autoCompletion, the result contains the fields to display or by default search fields.

The format is strict. This improvement add new field  displayFieldFormat to send a UEL schema that we want.

This commit introduce an example with LookupWorkEffort :

****
      <set field="displayFieldFormat" value="\${workEffortName} - \${groovy: description?.length() &gt; 20 ? description.substring(0, 20) + '…': description}"/>
****

We want display the workEffortName and the description limited to 20 chars. To forward the UEL string, we need to use the escape char \ like this the screen engine doesn't parse displayFieldFormat and let the ftl AjaxAutocompleteOptions.ftl realized the translation.
  • Loading branch information
nmalin authored Nov 13, 2024
1 parent d177648 commit 01bb124
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions applications/workeffort/widget/LookupScreens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ under the License.
<set field="viewSize" from-field="parameters.VIEW_SIZE" type="Integer" default-value="${viewSizeDefaultValue}"/>
<set field="entityName" value="WorkEffort"/>
<set field="searchFields" value="[workEffortId, workEffortName, description]"/>
<set field="displayFieldFormat" value="\${workEffortName} - \${groovy: description?.length() &gt; 20 ? description.substring(0, 20) + '…': description}"/>
</actions>
<widgets>
<decorator-screen name="LookupDecorator" location="component://common/widget/CommonScreens.xml">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ under the License.
<script type="text/javascript">
var autocomp = [
<#if autocompleteOptions?has_content>
<#if displayFieldFormat?has_content>
<#assign displayStringExpdander = Static["org.apache.ofbiz.base.util.string.FlexibleStringExpander"].getInstance(displayFieldFormat)>
</#if>
<#list autocompleteOptions as autocompleteOption>
{
<#assign displayString = ""/>
<#assign returnField = ""/>
<#if displayStringExpdander?has_content>
<#assign displayString = displayStringExpdander.expand(autocompleteOption.getAllFields())>
</#if>
<#list displayFieldsSet as key>
<#assign field = autocompleteOption.get(key)!>
<#if field?has_content>
<#if (key == context.returnField)>
<#assign returnField = field/>
<#else>
<#elseif !displayStringExpdander?has_content>
<#assign displayString = displayString + StringUtil.wrapString(field?string) + " ">
</#if>
</#if>
Expand Down

0 comments on commit 01bb124

Please sign in to comment.