Mi-Corporation Support

How can we help you today?

Event handling for multiple fields

Modified on: Tue, 25 Sep, 2018 at 9:49 AM

The Mobile Impact Platform lets designers handle multiple events, such as when a field gets data, within script code. This article illustrates how to handle events that may be triggered by multiple user actions.

As an example, let's assume a form that has the following fields:

City

State

Zipcode

Quantity

Cost

Total

And let's assume that when a user enters a zipcode, we want to programatically set the City & State fields. To do so, we'd first click on the AfterSetData event in the right hand side, which would insert code that looks like this:

Note that this event handler is passed a parameter named fieldName. This parameter is going to be set to the name of the field who's data has been set. This means that we want to check this parameter in order to take appropriate action. First, we'll add code for the zipcode handling. This would look something like the following:

Now, when the user enters a quantity we want to also calculate the total field. If we click on the AfterSetData event again, you'll note that your cursor is navigated to the already existing code snippet. It does not create another function. If you are copy and pasting code, you may be tempted to create code that looks something like this:

Of course, in reality, we'd also want to calculate this total not just when the quantity changes, but also when the cost changes. This can be handled with a simple "or" expression and the final code would look like this: