cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Dynamically change Snap's settings tab

j_angelevski
Contributor III

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โ€
image
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 ?

1 ACCEPTED SOLUTION

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.

View solution in original post

4 REPLIES 4

j_angelevski
Contributor III

@ptaylor any suggestions on this ?

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.

j_angelevski
Contributor III

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 ?

Sorry, but there isnโ€™t.