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
I recommend to not implement one huge form covering all use cases. This becomes complex and hard to maintain.
But, to answer your question, add a local variable "isModified" and default it to false. Then add a a!save() to all fields to update isModified to true(). Then use that status to add some logic to the submit button.
Now, check my first sentence ...
do u have any example to quote?
I tried this way and it seems it's not performing data comparison. Is there any other possible way, it can perform a logical comparison and gets enables button with the changes
Where and how are you saving the updates to the "local!data" variable (and/or its refernced variables)?
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(), ) ) }, {} ) ) ) )
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?
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.
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" ) } ) } ) )
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
Tan18 said: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.
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] ),
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.