You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by nm...@apache.org on 2024/11/13 08:17:51 UTC

(ofbiz-framework) branch release24.09 updated: Improved: Add display result format for auto-completion on lookup (OFBIZ-13173) (#853)

This is an automated email from the ASF dual-hosted git repository.

nmalin pushed a commit to branch release24.09
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/release24.09 by this push:
     new 38cb93168c Improved: Add display result format for auto-completion on lookup (OFBIZ-13173) (#853)
38cb93168c is described below

commit 38cb93168cf4151fad9af22964bdb9b4f451fe12
Author: Nicolas Malin <ni...@nereide.fr>
AuthorDate: Wed Nov 13 09:14:21 2024 +0100

    Improved: Add display result format for auto-completion on lookup (OFBIZ-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.
---
 applications/workeffort/widget/LookupScreens.xml                  | 1 +
 themes/common-theme/template/includes/AjaxAutocompleteOptions.ftl | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/applications/workeffort/widget/LookupScreens.xml b/applications/workeffort/widget/LookupScreens.xml
index 5ada5237ac..69771ac578 100644
--- a/applications/workeffort/widget/LookupScreens.xml
+++ b/applications/workeffort/widget/LookupScreens.xml
@@ -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">
diff --git a/themes/common-theme/template/includes/AjaxAutocompleteOptions.ftl b/themes/common-theme/template/includes/AjaxAutocompleteOptions.ftl
index b1b297ec96..2d378641c2 100644
--- a/themes/common-theme/template/includes/AjaxAutocompleteOptions.ftl
+++ b/themes/common-theme/template/includes/AjaxAutocompleteOptions.ftl
@@ -35,16 +35,22 @@ under the License.
 <script type="application/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>