Dynamic calculation when inputting data in editor
Dynamic calculation when inputting data in editor
Hello,
I have a table to calculate the marks of the student projects (see below). I would like to know how to do a dynamic calculation in the non-editable fields (in blue) instantly when I input some marks in the editable fields (in red). In other words, when I type some numbers in the editable fields, the non-editable fields will show the calculated numbers. And when I click the "Update" button, the showed calculated numbers will be updated to the database. Many thanks.
This question has accepted answers - jump to:
Answers
Use "dependent" with an array of the fields whose changes should trigger (re)calculation of your non-editable fields and set the fields accordingly. You might also want to use field().message() to display calculated results.
Here is an example from my own coding with lots of calculations and field setting
This is the result:
Thanks a lot !! It works perfectly well !!
How about if I want to change the background color of a non-editable field to red, when a calculated value is larger than 10. Is there any suggested codes? Thank you.
var diff = report_mark - presentation_mark;
if (diff > 10) {
// how to change the background color of a field named 'difference' to red
// this.field('difference').background-color(red); ??
}
field().input()
is the method you want:You'll want an
else
statement as well to remove the background colour should it become valid with additional input.Allan
@allan: looks good!
I did the same thing for groups of fields that I grouped using "className" like this:
And then I assigned bootstrap background classes to the fields of each group:
Looks like this; the green fields have class "bg-success"
That looks superb - nice one!
Allan