Support

  1. ggaillet
  2. Support
  3. Saturday, February 08 2020, 06:54 AM
  4.  Subscribe via email
hi!

Is it possible to create a number field or a text decimal field that displays the sum of three other fields of the same type? in other words, can we do operations between fields and display the result in another one?
Thanks.
admin Accepted Answer
Admin
Hi,
yes this is possible, but you need to create a simple plugin, follow this example:
- Download, Install and Enable Skeleton Plugin (you will find it at http://docs.easy-profile.com/index.php/article/triggers)
- Open file /plugins/jsn/skeleton/skeleton.php
- remove samples functions: triggerFieldAvatarUpdate, triggerProfileUpdate
- add function like this:
public function triggerProfileUpdate($user,&$data,$changed,$isNew){ 
// SUM
$data['field1'] = $data['field2'] + $data['field3'];
// CONCAT
$data['field1'] = $data['field2'] . $data['field3'];
// SUM FROM CHECKBOX OPTIONS,
// The checkbox can have multiple values (2 or more options), so the value is stored in JSON format
$values = (array) json_decode($data['field2']);
foreach($values as $value){
$data['field1'] += $value; // sum of options value
}
}

with this way you can do operations between fields, you need only to write your operation ;)
docs about our triggers at http://docs.easy-profile.com/index.php/article/triggers

NOTE: This code is not tested and not supported, this is only for example purpose. You need to have a minimum of PHP knowledges
  1. one week ago
  2. Support
  3. # 1
ggaillet Accepted Answer
Basic
Thanks. Can the fields be text with a format set to integer or do they have to be of type number?
The fields I want to add are text integer but the code you gave me is apparently returning nothing in the resulting field?
  1. one week ago
  2. Support
  3. # 2
ggaillet Accepted Answer
Basic
OK. I found that if the field is having a decimal, the sum is not done. Plus I don't know why but my integer fields accept only , for the decimal instead of the . Maybe that's the reason why the sum is not working when there is a number with a , ?
  1. one week ago
  2. Support
  3. # 3
admin Accepted Answer
Admin
Hi,
we recommend to use text field type, it is more flexible.
To restrict numeric values you can set "format allowed" option to "decimal" like screenshot.

in php the decimal separator is ".", so you need to convert all "," occurrences before the sum.
Attachments (1)
  1. one week ago
  2. Support
  3. # 4
ggaillet Accepted Answer
Basic
Thanks for your answer. My fields are defined now as Text and option decimal. But when using a "." I got an "error" message with the field highlighted in red. Only with a "," I can submit the new value without error. How can I change that so my users can use "." instead of ","?
Thanks.
  1. one week ago
  2. Support
  3. # 5
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Request Support

Support is currently Offline

Support Availability

Working days: Monday to Friday. The support staff is not available on weekends; in the most of cases tickets will not be answered during that time.

Reply time: Depending on the complexity of your support issue it's usually between a few minutes and 24 hours for paid members and about one week for free members. When we expect longer delays we will notify you.

Guidelines

Before you post: read the documentation and search the forums for an answer to your question.

When you post: include Site Details if you request a support (you can use the form below the reply in Site Details tab).

Auto Solved Question: If after a week the author of the post does not reply to a request by moderator, the question will be marked as resolved.

Language: only English

Search Users

Easy ProfileĀ® is not affiliated with or endorsed by Open Source Matters or the Joomla Project. Joomla is Free Software released under the GNU/GPL License.