Liberty Create – Mathematical Calculation and Validation using Fragment Callback and Fragment Validators
There is no direct way in Liberty Create Build Studio where we can perform a calculation and validation using multiple fields on client side, and show total or compare values between fields as we change any of the field values on form.
However, we have a solution! This can be achieved using the Code Studio – Fragment Callback and Fragment Validator.
This article will cover the steps on how to add and make use of Liberty Create Fragment callback to perform calculation and Fragment Validator to compare field values.
- Create a page with multiple decimal fields and mark Total(Calculated) as read-only using CSS (this will be calculated automatically).
- So, in the above screen, we are going to perform two operations:
- Calculation – Total (Calculated) = Consulting + Accommodation +Flight + Transportation +Tools + ((Consulting + Accommodation +Flight + Transportation +Tools) * Extra Share %age)
- Validation – Expense Limit > = Total (Calculate)
- In order to perform (calculation), we will be using Fragment Callback as we have to perform calculation as soon as any of the field value (Consulting, Accommodation, Flight, Transporation,Tools,Extra Share) changes.
- For (Vaidation), we will be using Fragment Validators.
- Let’s create field path references to point to the fields required for calculation.
- Click on References from Code Studio and Add Reference.
- Create reference for each of required fields for calculation (Consulting,Accomodation,Flight,Transportation,Tools, Extra Share,Expense Limit and Total Expense Amount).
Create Fragment Callback to Calculate the Total Expense Amount:
Select Fragment Callbacks under processors and click on Add New.
Enter Name and Click Create . Click on Code
Registration is required to view the full article.
Please login or register to access the full article.