04-07-2021 06:39 AM
Hello,
I was just wondering if it is possible to “dynamically” change the settings tab of a custom snap. What I mean by this is to dynamically change one field by changing some other field. For example let’s say I have two fields “Locale” and “Amount”
Let’s say that I want to change the “Amount” field to some other value if we select another locale. For example if I change from locale “es” to locale “en” I want to change the value of the “Amount” field to “40”. Or let’s say when I change from one locale to another I want another field to be “added” in the settings tab.
Is such a thing even possible ? I’ve searched the documentation and I found that the “Settings” tab of the snap is created at build time ( defineProperties method ), so I was just wondering if it is even possible to do such a thing ? Are there any “events” to handle this type of dynamic evaluation ?
Solved! Go to Solution.
04-09-2021 08:06 AM
The only dynamic functionality is enableIf, which you can attach to a property in the defineProperties method:
.enableIf("$.settings.locale.value == 'en'")
You can build compound conditions using the normal logical operators (&&, ||, !).
If locale had an expression toggle and you want to test whether it’s true or false, you would use “$.settings.locale.expression” in the expression. Unfortunately if the entry does contain an expression, you can’t actually test the result of evaluating that expression, since that would involve a call to the back end, which this doesn’t do. This is just testing the state of the UI controls in the browser. The way we deal with this current limitation in our snaps that use this feature is to enable a dependent property if the controlling property has a particular value and is not an expression, or it is an expression.
The term “enable” is a bit misleading because what it actually controls is visibility. When the condition is true, the control is visible, otherwise it’s hidden.
04-09-2021 02:56 AM
@ptaylor any suggestions on this ?
04-09-2021 08:06 AM
The only dynamic functionality is enableIf, which you can attach to a property in the defineProperties method:
.enableIf("$.settings.locale.value == 'en'")
You can build compound conditions using the normal logical operators (&&, ||, !).
If locale had an expression toggle and you want to test whether it’s true or false, you would use “$.settings.locale.expression” in the expression. Unfortunately if the entry does contain an expression, you can’t actually test the result of evaluating that expression, since that would involve a call to the back end, which this doesn’t do. This is just testing the state of the UI controls in the browser. The way we deal with this current limitation in our snaps that use this feature is to enable a dependent property if the controlling property has a particular value and is not an expression, or it is an expression.
The term “enable” is a bit misleading because what it actually controls is visibility. When the condition is true, the control is visible, otherwise it’s hidden.
04-12-2021 02:00 AM
Thanks @ptaylor.
I am looking for a way to dynamically update SnapType.TABLE rows ( dynamically adding more rows depending on another field ). The “enableIf” only helps to show/hide a particular field but it does not dynamically update any field. Is there a way to actually “add” more rows to a table based on another field ? What I actually want is when we select a value from the dropdown to update the number of rows based on the value of the dropdown. Is there any method to do this or some workaround ?
04-12-2021 08:23 AM
Sorry, but there isn’t.