Hi Angela,
That is a great question. We don’t have a natural way to support changing the displayed currency when a relationship is set to a record that holds the currency that the money field depends upon.
We will look to see if we can add support for this in a standard way. I tested a solution that will work for now, if you don’t mind a slightly complicated setup.
- In the Region selector fragment settings:
- Set “Trigger Event” (in “Advanced”) to “E1” (This will fire whenever the Region changes and declares to listening fragments that event “E1” happened)
- Add the Region Currency fragment setting into the form (or a dummy currency field - see below)
- Set its wrapper to “Hidden row” so it will not be seen by your user
- Select the Callback to run that will set its own value to the currency of the selected Region (code below)
- Set “Refresh on Event” to “E1”.
- Set “Trigger Event” to “E2”.
- In the Money field fragment settings:
- Set “Refresh on Event” to “E2”.
- Ensure that the “Dynamic currency” setting corresponds to the currency field added in step 2.
Here is the Callback Code I used in my quick test:
> // Get the record id of the selected Region from the dropdown field in the form
> var product_region = fragment_presenter.get_values()[cs.ref('product_region')];
>
> // Look up the currency associated with the Region in the database
> var currency_of_selected_region = cs.record(product_region).get(cs.ref('region_currency'));
>
> // Set the currency field in the input in the form
> fragment_presenter.set_value(currency_of_selected_region);
Note that the above setup will actually submit the region’s currency value. This should be fine because in theory it will always be set to the same value as the selected relation (although if you have no relation selected, that could cause the creation of a new Region).
In any case, it is better to prevent this. You could have a dummy currency field on the Product record that you use in place of the real one above. Or you could create a data processor (set in the form settings), to strip out the currency field from the submitted data.
Here is the data processor:
var form_values = params.fields;
// Remove the currency from the data to be saved
delete form_values.fields[cs.ref(“product_currency”)];
return form_values;
The above seeks to make use of our built-in, dynamic currency logic. But you might be able to cheat, by ignoring that and just specifying a prefix to show (like below, but with the dynamic currency). This might be awkward though to translate 3-digit ISO codes into symbols and have them displayed an htmlentities correctly.
fragment_presenter.set_setting(‘prefix’, ‘£’);
As I said above, we will endeavour to make this simplier very soon!
I’d be happy to talk it through on the phone if you’d like.
Paul