Save button should get enabled if changes are made to initial submission

A Score Level 1

Under the form, I have a save button that will be disabled after the form submission. The button should be enabled if any changes are made to the data or a comment is added.Any help will be appreciated.

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Lead Developer
    in reply to Tan18

    Where and how are you saving the updates to the "local!data" variable (and/or its refernced variables)?

  • 0
    A Score Level 1
    in reply to Mike Schmitt

    a!localVariables(
      local!data: {
        
           
            ri!datasubset,
            ri!transValue,
            ri!orgValue,
            ri!ageValue
          
        
      },
      local!originalData:a!refreshVariables(
      value:local!data,
      refreshOnReferenceVarChange:false()
      ),
        local!modified: not(
          exact(
            tostring(local!data),
            tostring(local!originalData)
          )
        ),
    
        a!formLayout(
          buttons: a!buttonLayout(
            primaryButtons: 
            if(
              ri!isEditable,
              {
                if(
                  ri!canSubmit,
                  a!buttonWidget(
                    label: cons!BUTTON_VAL_SUBMIT,
                    style: "PRIMARY",
                    submit: true(),
                    validate: true(),
                    value: cons!BUTTON_VAL_SUBMIT,
                    saveInto: ri!buttonAction,
                    disabled: 
                    if(
    
                      and(rule!APN_hasValue ( ri!SubmissionDate),local!originalData<>local!modified),
                     false(),
                     true(),
                    )
    
                  ),
                  {}
                ),
                a!buttonWidgetSubmit(
                  label: cons!BUTTON_VAL_SAVE,
                  style: if(
                    ri!canSubmit,
                    "NORMAL",
                    "PRIMARY"
                  ),
                  submit: true(),
                  validate: true(),
                  value: cons!BUTTON_VAL_SAVE,
                  saveInto: ri!buttonAction,
                  disabled: 
                  if(
    
                    and(rule!APN_hasValue ( ri!SubmissionDate),not(local!modified),
                    false(),
                    true(),
                  )
                )
              },
              {}
            )
          )
          )
        
      )

  • 0
    Certified Lead Developer
    in reply to Tan18

    I'm confused though, because the updated code you've attached here doesn't seem to have any places where local!data and/or any of the 4 RI variables it references, get modified whatsoever.  So how are you actually performing changes to the underlying data to verify that local!modified isn't working correctly?

  • 0
    Certified Lead Developer
    in reply to Tan18

    Also, this is not the correct name

    The actual function name is "a!refreshVariable()"

    Additionally the correct spelling of the parameter name is "refreshOnReferencedVarChange" - not "refreshOnReferenceVarChange".  The interface designer's built-in error messages should prompt you for these things.

  • 0
    Certified Lead Developer
    in reply to Tan18

    Here's a simplified, ready-to-paste example of exactly how this sort of thing can-and-should work, FWIW.

    a!localVariables(
      local!name: "Mike",
      local!date: today()-4,
      
      local!data: {
        local!name,
        local!date
        /*ri!datasubset,
        ri!transValue,
        ri!orgValue,
        ri!ageValue*/
      },
      local!originalData: a!refreshVariable(
        value: local!data,
        refreshOnReferencedVarChange: false()
      ),
      local!modified: not(
        exact(
          tostring(local!data),
          tostring(local!originalData)
        )
      ),
    
      a!formLayout(
        contents: {
          a!textField(
            label: "Name",
            value: local!name,
            saveInto: local!name
          ),
          a!dateField(
            label: "Date",
            value: local!date,
            saveInto: local!date
          ),
          a!richTextDisplayField(
            value: {
              a!richTextItem(
                text: "not modified...",
                showWhen: not(local!modified),
                style: "EMPHASIS",
                color: "SECONDARY"
              ),
              a!richTextItem(
                showWhen: local!modified,
                text: "Modified!",
                color: "POSITIVE",
                style: "STRONG"
              )
            }
          )
        }
      )
    )

  • 0
    A Score Level 1
    in reply to Mike Schmitt

    These mistakes happened as I updated my initial code in this thread but in designer, it's correctly spelled. But somehow I feel this logic is not working . Whenever I do some changes to data buttons are not getting enabled. Adding is modified rule input to all nested interfaces will be hard. it will break the correct working from

  • 0
    Certified Lead Developer
    in reply to Tan18
    Whenever I do some changes to data buttons are not getting enabled

    You should be troubleshooting this by viewing the values of the local variables in the interface designer's "local variables" pane as you enter new values for test inputs, etc.  For instance you should be able to see the value of "local!modified" change, not just judging by whether or not the buttons become enabled. 

    As always, I suggest you start with simpler code that you can understand, and work up from there only once you absolutely understand what's going on.  If it helps, see the simplified example code I posted above, which can be copied/pasted into a blank interface designer window and tested with.

  • 0
    A Score Level 1
    in reply to Mike Schmitt

    Yes, I checked, it's not doing the data comparison.so I added the other rule input for original value and used the following code for the interface with multiple child interfaces.It works when I remove indexing for one interface but with fv!index  I am getting error stating:

    Interface Definition: Expression evaluation error at function a!forEach [line 148]: Error in a!forEach() expression during iteration 1: Expression evaluation error : Invalid index (1) for null value of type SS_Data?list. Any suggestions

    local!changesMadeToData:a!forEach(
        items: ri!Data,
        expression: fv!item=ri!OrignalData[fv!index]
      ),

  • 0
    Certified Lead Developer
    in reply to Tan18

    I'm a little confused at the context here, but for times where you need to access an index (numeric position) in an array where you're not 100% sure that index will exist, you should use the index() function with a "default" parameter.