Share customization - Could not make the advanced searching with dropdown property to work?

cancel
Showing results for 
Search instead for 
Did you mean: 
sepgs2004
Established Member

Share customization - Could not make the advanced searching with dropdown property to work?

Jump to solution

I am using Alfresco Community 5.2. I used Alfresco Maven SDK 3.0 to generate AMPs for the repository tier and share UI tier. I did customization in the share config custom XML, etc.

Say, custom type A has a dropdown property (through a custom aspect and constraints). (Only in the try-alfresco-tomcat, I am able to do the following). Now in the Advanced Search, the property shows up as a dropdown with all the values (because of the customization). The first value is preselected for the dropdown (as naturally expected).

Now, whether I like it or not, it will become part of the search conditions (when I click search).
I cannot have it optionally in the search condition. Like, if I choose nothing, do not search by it. And if I choose a valid value from the dropdown, then search by it.

This search behavior can be accomplished for the text box search fields, right?
How could I do the same for dropdown custom property.

Gnanasekaran Sakthivel
1 Solution

Accepted Solutions
abhinavmishra14
Advanced

Re: Share customization - Could not make the advanced searching with dropdown property to work?

Jump to solution

You have two options, either you can use a custom form template for that property that will display all the values with a "" (empty) option or add the "" (empty) in constraint list in content model you have defined.

e.g., notice the empty <value>, this should resolve use case you have.  This is the simplest option.

<constraint name="demo:trialProductList" type="LIST">
      <parameter name="allowedValues">
        <list>
          <value></value>
          <value>Trial30</value>
          <value>Trial60</value>
.......
        </list>
      </parameter>
    </constraint>

Alternatively, you have to write a freemarker template, keep it in <yourShareModule>\src\main\resources\alfresco\web-extension\site-webscripts\com\demo\components\form\controls directory for example and use it as a template for the properties where you want to see an additonal empty option. You can take reference of out of the box "selectone.ftl" template and create your custom template that shows a blank option to avoid first value by default selected.

e.g.:

<field id="demo:trialProducts">
   <control
	  template="/com/demo/components/form/controls/select-menu-with-blank.ftl" />
</field>

 Example of select-menu-with-blank.ftl :

<#include "/org/alfresco/components/form/controls/common/utils.inc.ftl" />

<#if field.control.params.optionSeparator??>
   <#assign optionSeparator=field.control.params.optionSeparator>
<#else>
   <#assign optionSeparator=",">
</#if>
<#if field.control.params.labelSeparator??>
   <#assign labelSeparator=field.control.params.labelSeparator>
<#else>
   <#assign labelSeparator="|">
</#if>
<#if field.control.params.blankValueDefault??>
   <#assign blankValueDefault=field.control.params.blankValueDefault>
<#else>
   <#assign blankValueDefault="true">
</#if>

<#assign fieldValue=field.value>

<#if fieldValue?string == "" && field.control.params.defaultValueContextProperty??>
   <#if context.properties[field.control.params.defaultValueContextProperty]??>
      <#assign fieldValue = context.properties[field.control.params.defaultValueContextProperty]>
   <#elseif args[field.control.params.defaultValueContextProperty]??>
      <#assign fieldValue = args[field.control.params.defaultValueContextProperty]>
   </#if>
</#if>

<div class="form-field">
   <#if form.mode == "view">
      <div class="viewmode-field">
         <#if field.mandatory && !(fieldValue?is_number) && fieldValue?string == "">
            <span class="incomplete-warning"><img src="${url.context}/res/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
         </#if>
         <span class="viewmode-label">${field.label?html}:</span>
         <#if fieldValue?string == "">
            <#assign valueToShow=msg("form.control.novalue")>
         <#else>
            <#assign valueToShow=fieldValue>
            <#if field.control.params.options?? && field.control.params.options != "">
               <#list field.control.params.options?split(optionSeparator) as nameValue>
                  <#if nameValue?index_of(labelSeparator) == -1>
                     <#if nameValue == fieldValue?string || (fieldValue?is_number && fieldValue?c == nameValue)>
                        <#assign valueToShow=nameValue>
                        <#break>
                     </#if>
                  <#else>
                     <#assign choice=nameValue?split(labelSeparator)>
                     <#if choice[0] == fieldValue?string || (fieldValue?is_number && fieldValue?c == choice[0])>
                        <#assign valueToShow=msgValue(choice[1])>
                        <#break>
                     </#if>
                  </#if>
               </#list>
            </#if>
         </#if>
         <span class="viewmode-value">${valueToShow?html}</span>
      </div>
   <#else>
      <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
      <#if field.control.params.options?? && field.control.params.options != "">
         <select id="${fieldHtmlId}" name="${field.name}" tabindex="0"
               <#if field.description??>title="${field.description}"</#if>
               <#if field.control.params.size??>size="${field.control.params.size}"</#if> 
               <#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
               <#if field.control.params.style??>style="${field.control.params.style}"</#if>
               <#if field.disabled  && !(field.control.params.forceEditable?? && field.control.params.forceEditable == "true")>disabled="true"</#if>>
               <!-- Add a default blank option first, selected if there is no existing value -->
               <option value="" <#if blankValueDefault = "true" ||  !(fieldValue??)> selected="selected"</#if>></option>
               <#list field.control.params.options?split(optionSeparator) as nameValue>
                  <#if nameValue?index_of(labelSeparator) == -1>
                     <#-- Additional double quotes for exact term query -->
                     <option value='"${nameValue?html}"'<#if blankValueDefault = "false" && (nameValue == fieldValue?string || (fieldValue?is_number && fieldValue?c == nameValue))> selected="selected"</#if>>${nameValue?html}</option>
                  <#else>
                     <#assign choice=nameValue?split(labelSeparator)>
                     <option value='"${choice[0]?html}"'<#if blankValueDefault = "false" && (choice[0] == fieldValue?string || (fieldValue?is_number && fieldValue?c == choice[0]))> selected="selected"</#if>>${msgValue(choice[1])?html}</option>
                  </#if>
               </#list>
         </select>
         <@formLib.renderFieldHelp field=field />
      <#else>
         <div id="${fieldHtmlId}" class="missing-options">${msg("form.control.selectone.missing-options")}</div>
      </#if>
   </#if>
</div>

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View solution in original post

4 Replies
abhinavmishra14
Advanced

Re: Share customization - Could not make the advanced searching with dropdown property to work?

Jump to solution

You have two options, either you can use a custom form template for that property that will display all the values with a "" (empty) option or add the "" (empty) in constraint list in content model you have defined.

e.g., notice the empty <value>, this should resolve use case you have.  This is the simplest option.

<constraint name="demo:trialProductList" type="LIST">
      <parameter name="allowedValues">
        <list>
          <value></value>
          <value>Trial30</value>
          <value>Trial60</value>
.......
        </list>
      </parameter>
    </constraint>

Alternatively, you have to write a freemarker template, keep it in <yourShareModule>\src\main\resources\alfresco\web-extension\site-webscripts\com\demo\components\form\controls directory for example and use it as a template for the properties where you want to see an additonal empty option. You can take reference of out of the box "selectone.ftl" template and create your custom template that shows a blank option to avoid first value by default selected.

e.g.:

<field id="demo:trialProducts">
   <control
	  template="/com/demo/components/form/controls/select-menu-with-blank.ftl" />
</field>

 Example of select-menu-with-blank.ftl :

<#include "/org/alfresco/components/form/controls/common/utils.inc.ftl" />

<#if field.control.params.optionSeparator??>
   <#assign optionSeparator=field.control.params.optionSeparator>
<#else>
   <#assign optionSeparator=",">
</#if>
<#if field.control.params.labelSeparator??>
   <#assign labelSeparator=field.control.params.labelSeparator>
<#else>
   <#assign labelSeparator="|">
</#if>
<#if field.control.params.blankValueDefault??>
   <#assign blankValueDefault=field.control.params.blankValueDefault>
<#else>
   <#assign blankValueDefault="true">
</#if>

<#assign fieldValue=field.value>

<#if fieldValue?string == "" && field.control.params.defaultValueContextProperty??>
   <#if context.properties[field.control.params.defaultValueContextProperty]??>
      <#assign fieldValue = context.properties[field.control.params.defaultValueContextProperty]>
   <#elseif args[field.control.params.defaultValueContextProperty]??>
      <#assign fieldValue = args[field.control.params.defaultValueContextProperty]>
   </#if>
</#if>

<div class="form-field">
   <#if form.mode == "view">
      <div class="viewmode-field">
         <#if field.mandatory && !(fieldValue?is_number) && fieldValue?string == "">
            <span class="incomplete-warning"><img src="${url.context}/res/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
         </#if>
         <span class="viewmode-label">${field.label?html}:</span>
         <#if fieldValue?string == "">
            <#assign valueToShow=msg("form.control.novalue")>
         <#else>
            <#assign valueToShow=fieldValue>
            <#if field.control.params.options?? && field.control.params.options != "">
               <#list field.control.params.options?split(optionSeparator) as nameValue>
                  <#if nameValue?index_of(labelSeparator) == -1>
                     <#if nameValue == fieldValue?string || (fieldValue?is_number && fieldValue?c == nameValue)>
                        <#assign valueToShow=nameValue>
                        <#break>
                     </#if>
                  <#else>
                     <#assign choice=nameValue?split(labelSeparator)>
                     <#if choice[0] == fieldValue?string || (fieldValue?is_number && fieldValue?c == choice[0])>
                        <#assign valueToShow=msgValue(choice[1])>
                        <#break>
                     </#if>
                  </#if>
               </#list>
            </#if>
         </#if>
         <span class="viewmode-value">${valueToShow?html}</span>
      </div>
   <#else>
      <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
      <#if field.control.params.options?? && field.control.params.options != "">
         <select id="${fieldHtmlId}" name="${field.name}" tabindex="0"
               <#if field.description??>title="${field.description}"</#if>
               <#if field.control.params.size??>size="${field.control.params.size}"</#if> 
               <#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
               <#if field.control.params.style??>style="${field.control.params.style}"</#if>
               <#if field.disabled  && !(field.control.params.forceEditable?? && field.control.params.forceEditable == "true")>disabled="true"</#if>>
               <!-- Add a default blank option first, selected if there is no existing value -->
               <option value="" <#if blankValueDefault = "true" ||  !(fieldValue??)> selected="selected"</#if>></option>
               <#list field.control.params.options?split(optionSeparator) as nameValue>
                  <#if nameValue?index_of(labelSeparator) == -1>
                     <#-- Additional double quotes for exact term query -->
                     <option value='"${nameValue?html}"'<#if blankValueDefault = "false" && (nameValue == fieldValue?string || (fieldValue?is_number && fieldValue?c == nameValue))> selected="selected"</#if>>${nameValue?html}</option>
                  <#else>
                     <#assign choice=nameValue?split(labelSeparator)>
                     <option value='"${choice[0]?html}"'<#if blankValueDefault = "false" && (choice[0] == fieldValue?string || (fieldValue?is_number && fieldValue?c == choice[0]))> selected="selected"</#if>>${msgValue(choice[1])?html}</option>
                  </#if>
               </#list>
         </select>
         <@formLib.renderFieldHelp field=field />
      <#else>
         <div id="${fieldHtmlId}" class="missing-options">${msg("form.control.selectone.missing-options")}</div>
      </#if>
   </#if>
</div>

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
sepgs2004
Established Member

Re: Share customization - Could not make the advanced searching with dropdown property to work?

Jump to solution

One problem I am facing is, since the property is defined as integer or numeric, I am seeing an exception thrown while loading the page. This exception is similar to numberformat exception (trying to convert the empty space into numeric)

<property name="demo:Year_Single">
  <title>Fiscal Year</title>
  <type>d:int</type>
  <mandatory>false</mandatory>
  <index enabled="true">
    <tokenised>true</tokenised>
    <facetable>true</facetable>
  </index>
  <constraints>
    <constraint ref="demo:yearValuesList" />
  </constraints>
</property>


And the year list is defined as a constraint

<constraint name="demo:yearValuesList" type="LIST">
  <parameter name="allowedValues">
  <list>
    <value></value>
    <value>2008</value>
    <value>2009</value>
    <value>2010</value>
    <value>2011</value>
    <value>2012</value>
    …more...
  </list>
</parameter>
<parameter name="caseSensitive">
  <value>true</value>
</parameter>
<parameter name="sorted">
  <value>false</value>
</parameter>
</constraint>

I could change the type to text. But, is there a way to deal with this numeric conversion issue?
In regular web page frameworks, some negative number could be used to represent null or no selection. 

Gnanasekaran Sakthivel
abhinavmishra14
Advanced

Re: Share customization - Could not make the advanced searching with dropdown property to work?

Jump to solution

I don't think so. You have empty value in the list and type is d:int hence error is expected. Either

- convert the property to d:text

or

- remove empty from the constraint list and create a field template (e.g. custom template, selectone-with-blank.ftl) to show an additional empty value when share form loads. 

example of custom template: 

https://github.com/rjmfernandes/share-custom-form-controls/blob/master/share-custom-fc-share/src/mai... 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
abhinavmishra14
Advanced

Re: Share customization - Could not make the advanced searching with dropdown property to work?

Jump to solution

Glad it worked for you. good luck @sepgs2004 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)