ddraper

Aikau 1.0.91 - AutoSetConfig Updates

Blog Post created by ddraper on Oct 20, 2016

In Aikau 1.0.91 you'll find that there is an update to the autoSetConfig that could be applied to any form control. The ability to automatically set form control values based on changes to the value of other fields has always been present in Aikau, however it was only possible to configure specific values to set. For example you could do something like this:

 

{
   id: "SOURCE",
   name: "alfresco/forms/controls/Select", 
   config: {
      fieldId: "SOURCE_FIELD",
      label: "Choose from these...",
      name: "source",
      value: "",
      optionsConfig: {
         fixed: [
            { label: "One", value: "1"},
            { label: "Two", value: "2"},
            { label: "Three", value: "3"}
         ]
      }
   }
},
{
   id: "TARGET",
   name: "alfresco/forms/controls/TextBox",
   config: {
      name: "target",
      label: "...to set this",
      autoSetConfig: [
         {
            rulePassValue: "Option 3 Selected",
            ruleFailValue: "",
            rules: [
               {
                  targetId: "SOURCE_FIELD",
                  is: ["3"]
               }
            ]
         }
      ]
   }
}

 

In the above example the TARGET field would automatically have its value set to be "Option 3 Selected" whenever the user selected "Three" from the SOURCE field select menu. This facility was provided to enable hidden fields to be configured and is used effectively for this purpose by the InlineEditProperty renderer.

 

In the course of implementing the Inline Advanced Search we uncovered a use case where it was necessary for one field to automatically copy the value of another.  The reason why you might want to do this is in order to set the same value for multiple parameters. In the inline advanced search example there is the following model snippet:

 

{
   name: "alfresco/forms/controls/Select",
   config: {
      fieldId: "SELECT_FORM",
      label: "Look for",
      description: "This indicates the type of thing that you want to search for",
      name: "itemId",
      optionsConfig: {
         fixed: [
            {
               label: "Content", value: "cm:content"
            },
            {
               label: "Folder", value: "cm:folder"
            }
         ]
      }
   }
},
{
   name: "alfresco/forms/controls/TextBox",
   config: {
      fieldId: "DATA_TYPE",
      name: "formConfig.formSubmissionPayloadMixin.datatype",
      autoSetConfig: [
         {
            copyRule: {
               targetId: "SELECT_FORM"
            }
         }
      ],
      visibilityConfig: {
         initialValue: false
      }
   }
}

 

Here we have a hidden TextBox that is automatically updated to have the value of the advanced search form selected by the user. The autoSetConfig object now supports the copyRule attribute (which is only considered if rulePassValue or ruleFailValue are not provided). The targetId attribute within it indicates the field whose value should be copied.

 

The key difference between these two fields is the name attribute. The hidden field name attribute is targeting the autoSavePublishPayload value (see below). This is necessary in order to ensure that the "datatype" being searched for is included in the search payload.

 

autoSavePublishPayload: {
   itemKind: "type",
   mode: "edit",
   formId: "search",
   alfSuccessTopic: "ADV_SEARCH_FORM_RETRIEVED",
   formConfig: {
      okButtonLabel: "Search",
      okButtonPublishTopic: "ALF_ADVANCED_SEARCH",
      formSubmissionPayloadMixin: {
         alfResponseScope: "ADV_SEARCH_"
      },
      widgetsBefore: [
         {
            name: "alfresco/forms/controls/TextBox",
            config: {
               label: "Keywords",
               name: "searchTerm"
            }
         }
      ]
   }
}

 

This is a great example of how Aikau is able to enhance existing capabilities in a backwards compatible way. If you have any use cases that Aikau fails to address then please feel free to reach out to me either in the comments below, the discussion forums or as an issue on the Aikau GitHub repository.

Outcomes