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
  • 0
    Certified Lead Developer

    Set a LOAD variable (or if on 19.2, a localVariable with no autorefresh) equal to the original value of the data used to populate the grid.  Then set a with / autorefreshing variable that compares the original data with the current data, which evaluates to (for example) true() if changes have been made.  Use that variable to help determine the state of the SAVE button.  And finally, when SAVE is clicked, you would by some means cause the "original value" variable to be updated with the current data.

  • I actually have a column as editable--text which iam saving if any editing to the description column also...How can I recognise those changes made to each row and enable the save button based on that

  • 0
    Certified Lead Developer
    in reply to RAHUL GANJI

    The method I described should still be sufficient I think.  Or are you trying to recognize changes on a row-by-row basis?  If you only have one SAVE button for the whole form (which was my assumption), then you shouldn't need to worry about this.

  • +1
    Certified Lead Developer
    in reply to RAHUL GANJI

    Here's my quick version of what I was thinking of.  I In my example the main data is in local!itemList, though in a real implementation that could be replaced with a rule input value feeding in external (and editable) data.  The with() variable takes care of keeping track of whether any changes have been made, with the added bonus that it'll turn back off if changes are reverted.

    load(
      local!itemList: {
        {
          item: "Sofa",
          status: "unoccupied"
        },
        {
          item: "TV",
          status: "off"
        }
      },
      local!itemListOriginalValue: local!itemList,
      with(
        local!changesMade: not(
          exact(
            tostring(local!itemList),
            tostring(local!itemListOriginalValue)
          )
        ),
        
        a!formLayout(
          contents: {
            a!gridLayout(
              headerCells: {
                a!gridLayoutHeaderCell(
                  label: "Item"
                ),
                a!gridLayoutHeaderCell(
                  label: "Status"
                )
              },
              rows: a!forEach(
                local!itemList,
                a!gridRowLayout(
                  contents: {
                    a!textField(
                      value: fv!item.item,
                      readonly: true()
                    ),
                    a!textField(
                      value: fv!item.status,
                      saveInto: fv!item.status,
                      readOnly: false()
                    )
                  }
                )
              )
            )
          },
          buttons: a!buttonLayout(
            primaryButtons: a!buttonWidget(
              label: "SAVE",
              style: "PRIMARY",
              disabled: not(local!changesMade),
              saveInto: {
                a!save(
                  local!itemListOriginalValue,
                  local!itemList
                )
              }
            )
          )
        )
      )
    )

Reply
  • +1
    Certified Lead Developer
    in reply to RAHUL GANJI

    Here's my quick version of what I was thinking of.  I In my example the main data is in local!itemList, though in a real implementation that could be replaced with a rule input value feeding in external (and editable) data.  The with() variable takes care of keeping track of whether any changes have been made, with the added bonus that it'll turn back off if changes are reverted.

    load(
      local!itemList: {
        {
          item: "Sofa",
          status: "unoccupied"
        },
        {
          item: "TV",
          status: "off"
        }
      },
      local!itemListOriginalValue: local!itemList,
      with(
        local!changesMade: not(
          exact(
            tostring(local!itemList),
            tostring(local!itemListOriginalValue)
          )
        ),
        
        a!formLayout(
          contents: {
            a!gridLayout(
              headerCells: {
                a!gridLayoutHeaderCell(
                  label: "Item"
                ),
                a!gridLayoutHeaderCell(
                  label: "Status"
                )
              },
              rows: a!forEach(
                local!itemList,
                a!gridRowLayout(
                  contents: {
                    a!textField(
                      value: fv!item.item,
                      readonly: true()
                    ),
                    a!textField(
                      value: fv!item.status,
                      saveInto: fv!item.status,
                      readOnly: false()
                    )
                  }
                )
              )
            )
          },
          buttons: a!buttonLayout(
            primaryButtons: a!buttonWidget(
              label: "SAVE",
              style: "PRIMARY",
              disabled: not(local!changesMade),
              saveInto: {
                a!save(
                  local!itemListOriginalValue,
                  local!itemList
                )
              }
            )
          )
        )
      )
    )

Children