cancel
Showing results for 
Search instead for 
Did you mean: 

How to reset aikau form field values?

manav
Confirmed Champ
Confirmed Champ

var myForm = {
            name: "alfresco/forms/DynamicForm",
            config: {
              setValueTopic: "SET_FORM_VALUE",
              widgets: [
                {
                  name: "alfresco/forms/controls/TextBox",
                  config: {
                    name: "prop_1",
                    label: "Property 1"
                  }
                },
                {
                  name: "alfresco/forms/controls/TextBox",
                  config: {
                    name: "prop_2",
                    label: "Property 2"
                  }
                },
                {
                  name: "alfresco/forms/controls/DateTextBox",
                  config: {
                    name: "prop_3",
                    label: "Property 3 - date"
                  }
                },
              ],
              widgetsAdditionalButtons: [
                {
                  name: "alfresco/buttons/AlfButton",
                  config: {
                    updatePayload: false,
                    label: "Reset",
                    publishTopic: "RESET",
                    publishGlobal: true,
                    publishPayload:{ widgets:
                         [{
                         id: "RESET_FORM",
                         name: "alfresco/menus/AlfMenuBarItem",
                         config: {
                           label: "Reset Form",
                           publishTopic: "SET_FORM_VALUE",
                           publishPayload: {
                             prop_1: "",
                             prop_2: "",
                             prop_3: null
                           }
                         }
                       }]}
                  }
                }
              ],
                   
                    showOkButton : true,
                    okButtonLabel : "Save",
                    showCancelButton : false,
                    cancelButtonLabel : "Cancel",
                    setValueTopic : "RESET",
                    setValueTopicGlobalScope : true,

                    // Specify the TOPIC here
                    okButtonPublishTopic : "ALF_CRUD_CREATE",
                    okButtonPublishGlobal : true,
                    okButtonPublishPayload : {
                         // Specify the URL here to POST the data
                         url : "/sample/test",
                    }
                   
               }

           
          };

// Add the form and services to the JSON MODEL
model.jsonModel = {
     widgets : [ {
          id : "SET_PAGE_TITLE",
          name : "alfresco/header/SetTitle",
          config : {
               title : "Create Title"
          }
     }, myForm ],
     services : [ "alfresco/services/CrudService"

     ]
};
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I found a link that how to reset a form 

Resetting form 

https://community.alfresco.com/community/ecm/blog/2016/09/19/clearing-aikau-form-fields 
but this does't working for me,

I don't know where i am wrong.

// Create the form here
var formValue = {
            text: "Some value"
          };

          var myForm = {
            name: "alfresco/forms/Form",
            config: {
              setValueTopic: "RESET",
              setValueTopicGlobalScope: true,
              okButtonPublishTopic: "MY_TOPIC",
              widgets: [
                {
                  name: "alfresco/forms/controls/TextBox",
                  config: {
                    fieldId: "FIELD1",
                    label: "A TextBox",
                    name: "text"
                  }
                }
              ],
              widgetsAdditionalButtons: [
                {
                  name: "alfresco/buttons/AlfButton",
                  config: {
                    updatePayload: false,
                    label: "Reset",
                    publishTopic: "RESET",
                    publishGlobal: true,
                    publishPayload: formValue
                  }
                }
              ],
              value: formValue
            }
          };

// Add the form and services to the JSON MODEL
model.jsonModel = {
     widgets : [ {
          id : "SET_PAGE_TITLE",
          name : "alfresco/header/SetTitle",
          config : {
               title : "Create Title"
          }
     }, myForm ]
};

While clicking on reset button it is not clearing form field values.
please help.

1 REPLY 1

aviriel
Confirmed Champ
Confirmed Champ

The button should not be inside the form, add alfButton after the form, not as "additional buttons". Then it will work. Maybe it also can work if you play a bi with scopes, but I don't know a solution, I just added a button after the form and used custom css to draw it on the same line Smiley Happy