Dynamically change Snap's settings tab
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 ?
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.