Submit button being disabled if no changes are made to the editable grid

Under the grid, display a SAVE button. The button should be disabled by default.
If any changes are made to the grid (i.e. if a row is added, a row is removed, or data entered for a row is changed), the button should be enabled. After the button is clicked, it should become disabled again. Any help will be appreciated.

  Discussion posts and replies are publicly visible

Parents
  • Hello ,

    Please check if below code snippet works for you.Look for this local variable  local!submitDisabled. 

    load(
      local!submitDisabled: true,
    
      
      local!departments: {
        "Finance",
        "Human Resources",
        "Marketing",
        "Sales",
        "IT"
      },
      local!categories: {
        "Hardware",
        "Software",
        "Office Supplies",
        "Miscellaneous"
      },
      local!addresses: {
        {
          id: 1,
          shippingAddress: "123 Main St",
          unit: "",
          city: "Springfield",
          stateOrProvince: "AL",
          zipCode: "36784"
        },
        {
          id: 2,
          shippingAddress: "62201 Oak Blvd",
          unit: "",
          city: "Phoenix",
          stateOrProvince: "AZ",
          zipCode: "85032"
        },
        {
          id: 3,
          shippingAddress: "872 Park Ave",
          unit: "179",
          city: "Milwaukee",
          stateOrProvince: "WI",
          zipCode: "53201"
        },
        {
          id: 4,
          shippingAddress: "11955 Democracy Dr",
          unit: "1700",
          city: "Reston",
          stateOrProvince: "VA",
          zipCode: "20190"
        }
      },
      a!formLayout(
        label: "New Purchase Request",
        contents: {
          a!gridLayout(
            label: "Items",
            headerCells: {
              a!gridLayoutHeaderCell(
                label: "Description"
              ),
              a!gridLayoutHeaderCell(
                label: "Category"
              ),
              a!gridLayoutHeaderCell(
                label: "Qty",
                align: "RIGHT"
              ),
              a!gridLayoutHeaderCell(
                label: "Unit Price",
                align: "RIGHT"
              )
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(
                width: "DISTRIBUTE",
                weight: 3
              ),
              a!gridLayoutColumnConfig(
                width: "DISTRIBUTE",
                weight: 3
              ),
              a!gridLayoutColumnConfig(
                width: "DISTRIBUTE"
              ),
              a!gridLayoutColumnConfig(
                width: "DISTRIBUTE",
                weight: 2
              )
            },
            rows: {
              a!forEach(
                items: ri!purchaseRequest.items,
                expression: a!gridRowLayout(
                  contents: {
                    a!textField(
                      value: fv!item.desc,
                      saveInto: {
                        fv!item.desc,
                        a!save(
                          local!submitDisabled,
                          false
                        )
                      },
                      required: true,
                      validations: {
                        if(
                          and(
                            not(
                              isnull(
                                fv!item.desc
                              )
                            ),
                            len(
                              fv!item.desc
                            ) => 100
                          ),
                          "Description must be less than 100 characters",
                          ""
                        )
                      },
                      validationGroup: "main"
                    ),
                    a!dropdownField(
                      placeholderLabel: "--- Select a Category ---",
                      choiceLabels: local!categories,
                      choiceValues: local!categories,
                      value: fv!item.category,
                      saveInto: {
                        fv!item.category,
                        a!save(
                          local!submitDisabled,
                          false
                        )
                      },
                      required: true,
                      validationGroup: "main"
                    ),
                    a!integerField(
                      value: fv!item.qty,
                      saveInto: {
                        fv!item.qty,
                        a!save(
                          local!submitDisabled,
                          false
                        )
                      },
                      required: true,
                      validations: {
                        if(
                          tointeger(
                            fv!item.qty
                          ) < 1,
                          "Quantity must be greater than zero",
                          ""
                        )
                      },
                      validationGroup: "main",
                      align: "RIGHT"
                    ),
                    a!floatingPointField(
                      value: fv!item.unitPrice,
                      saveInto: {
                        fv!item.unitPrice,
                        a!save(
                          local!submitDisabled,
                          false
                        )
                      },
                      required: true,
                      validations: {
                        if(
                          todecimal(
                            fv!item.unitPrice
                          ) < 0,
                          "Price must be greater than zero",
                          ""
                        )
                      },
                      validationGroup: "main",
                      align: "RIGHT"
                    )
                  }
                )
              ),
              a!gridRowLayout(
                contents: {
                  a!textField(
                    readOnly: true
                  ),
                  a!textField(
                    readOnly: true
                  ),
                  a!textField(
                    readOnly: true
                  ),
                  a!textField(
                    value: "Total",
                    readOnly: true,
                    align: "RIGHT"
                  )
                }
              )
            },
            addRowLink: a!dynamicLink(
              label: "Add New Item",
              saveInto: {
                a!save(
                  local!submitDisabled,
                  false
                ),
                a!save(
                  ri!purchaseRequest.items,
                  append(
                    ri!purchaseRequest.items,
                    {
                      desc: "",
                      category: "",
                      qty: null,
                      unitPrice: null
                    }
                  )
                )
              }
            ),
            rowHeader: 1
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              saveInto: {},
              submit: true,
              style: "PRIMARY",
              /* Prevent form submission while a new address is being configured */
              disabled: local!submitDisabled,
              validationGroup: "main"
            )
          },
          secondaryButtons: {
            a!buttonWidget(
              label: "Cancel",
              value: true,
              saveInto: ri!cancel,
              submit: true,
              validate: false
            )
          }
        )
      )
    )

  • thats working for the attaching of a new document to the grid but it is not working for the editable column in the grid when the description in the column changes and we need to enable the submit button for that

Reply Children
No Data