Call function when a series of steps are completed

I have a shipping interface page that should create a shipment when a series of checks have been completed:

  • Has the user entered an address
  • Is the address valid
  • Has the user entered the box dimensions
  • Is the scale weight greater than 0

Each of these checks has a value in Page Data. When they are all “true”, I want to call a create shipment function.

May I get a suggestion on how to do this? Would you create event listeners for the Page Data values, and when they change, check the other values to see if they are also true and then call the function?

Thanks,
Tim

Are the individual values (email address, box dimensions, weight) entered through dedicated form fields? if so, you could have validator logic that runs as soon as the user enters the data and if it is invalid, highlight the corresponding field. If it is valid, you could set a flag in the data model indicating that the field’s data is valid.

Regards,
Mark

Some yes, some no.

For example, the user might enter the address and then click a button to validate the result. So one input, one process running to return a true/false on the validity of the address.

I could call a check function every time one of the different things changes, but I wanted to see if there was a “smarter” way to do it.

Tim

Keep in mind that any logic added to data-bindable properties will run when the underlying data model changes. There will have to be a final check that ensures that all data is entered properly. I would use binary logic to set bits in a numeric flag. The bits would indicate the validity of a corresponding data field. This will make it easier to do the final check - simply comparing the numeric flag with a value that should be there when everything is valid.

Hope this helps.

Mark

I currently set a true/false in Page Data for each step. Are you saying that would change?

Can you describe what the underlying data model would be in this instance?

For the final check, are you suggesting a series of checks incrementing a value and then checking that value to make sure it is what the expected value should be?

numericFlag = 0;

if (check1){

numericFlag + 1;

}

if (check2){

numericFlag + 1;

}

if (check3){

numericFlag + 1;

}

if (numericFlag = 3){

do stuff!

} else {

do not do stuff

}

I was describing an approach using binary logic to use individual bits of a number as flags indicating whether the corresponding field is valid or not. For example, suppose there are 4 UI fields. Each field has a position in some special integer where you flip bits. Here’s the binary representation of that value:

UI field 1 has a valid value:

0001

UI fields 1 and 3 have valid values:

0101

All fields have valid values:

1111

1111 binary is 15 decimal. So your logic which determines if the function should be invoked would be checking the “bit flags” value for 15

Here’s a demo page with that approach:
https://www.backendless.us/api/files/ui-builder/containers/support/index.html?page=binaryfields

It does require some JS code, however, I just use ChatGPT to generate the JS functions, so technically I didn’t have to write any code at all… :wink:

That is cool for a bunch of reasons, thanks @mark-piller!