Sometimes there is need for automatically calculating values based on other values. Yes, we can use calculated fields (SQL) on serverside to do so. In some cases I'd like to calculate and show already on client side in Detail View. Next version of our AppGini Helper Javascript Library will have simple functions for auto-calculating values of fields based on values of other fields while editing.
Please note The features shown here will be part of next version of AppGiniHelper Javascript Library, not current version. Next version will be published in 2022.
Check out this sample project:
- Field
full_name
... - having caption
Full name
... - is not readonly here (important) ...
- but unique ...
- and required ...
Same settings have been applied to field identifier
.
Table of Contents
Calculate full_name
field
Now let's create our first sample record. See how fields Identifier and Full name are reaonly now and will be auto-filled when entering data into First name and Last name fields:
After insert, we now have that new record including the calculated fields:
// file: hooks/contacts-dv.js // get a handle to detail view var dv = AppGiniHelper.dv; // calculate field "full_name" // concat values of last_name, first_name, middle_names // default separator: ", " dv.getField("full_name").setFunction(["last_name", "first_name", "middle_names"]);
Serverside check for uniqueness
Let's try to create another record and let's make use of AppGini's automatic check for uniqueness.
For this it is important to check the unique flag in your project:
Please note that we already have created a record before, having full_name
= "Setzer, Jan".
After automatically evaluation of the full_name
field, AppGini will check the value against the database on serverside and mark the field.
Please also note that the save-button (insert-button) will be disabled automatically.
The combination of AppGini's serverside check of unique constraints and AppGini Helper's clientside auto-calculation is very powerful, if you ask me.
Different separator (“glue”)
If you need a different separator, pass it as 2nd parameter:
// custom separator: " / " dv.getField("full_name").setFunction(["last_name", "first_name", "middle_names"], " / ");
Next: More complex calculations
In this example I have just concatenated values of existing fields as strings. But there is much more in next lesson. See page 2.