[SOLVED] [#8796] Populate Field with Calulcations of multiple other fields

2 years 4 months ago - 2 years 4 months ago #327271 by cagoffice
Hi,
We have a few fields that can take a percent between 0 and 100 increments of 10. there are 5 fields and we can to display the total in another field showing if they have gone over 100. This will allow the user a visual representation of the 5 fields entered. This will be done on the registration form. So we have built out the five dropdowns and then were using the query field to select and add the other fields but the last field never populates or shows a message. Any help would be greatly appreciated.

Fields we can just use:
Percent fields - field1, field2, field3, field4, field5 all as dropdown with 0 - 100
total field is text field showing sum of field1 to field5

Thanks so much,

Please Log in to join the conversation.

2 years 4 months ago #327290 by krileon
I recommend using a Code field instead which helps reduce the number of queries your site has to make. Also gives access to the many math functions PHP has built int. Example as follows using a Code field provided by CB Code Field.

Template: Same as Global
Code (PHP):
return (int) '[cb_FIELD_1]' + (int) '[cb_FIELD_2]' + (int) '[cb_FIELD_3]' + (int) '[cb_FIELD_4]' + (int) '[cb_FIELD_5]';

Now for this to work on the registration field you need the field to refresh its display when any other the other fields values change. To do that you'll need CB Core Fields Ajax. Once installed and published edit your code field and under Integrations > CB Core Fields Ajax configure the following.

Update On: cb_FIELD_1, cb_FIELD_2, cb_FIELD_3, cb_FIELD_4, cb_FIELD_5
Display Empty Update On: Disable

Query field won't work in a similar situation during registration since the user doesn't exist yet so there's nothing to query.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

2 years 4 months ago #327324 by cagoffice
Hello,
I have added and made adjustments as you suggested but the field still shows zero. I have adjusted all the dropdown items to be code dropdowns as well. Is there code that needs to be included there or are all the calls from the total field?

Part of the message is hidden for the guests. Please log in or register to see it.


Any help is greatly appreciated.
Thanks,

Please Log in to join the conversation.

2 years 4 months ago #327339 by krileon

This is our ajax call

What do you mean by this? You're making your own ajax call? From where and for what? Your code looks fine. The problem is likely how you're trying to access the field.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

2 years 4 months ago #327346 by cagoffice
Sorry I just meant this is the call we are using under the parameters tab > code for the "total" code field.
It still will not calculate anything with a total. Could this be the issue with the registration. Would this work as a validation?
Any help is greatly appreciated.
Thanks,

Please Log in to join the conversation.

2 years 4 months ago #327351 by krileon
Ok, was able to confirm the issue. It's due to our CBuser API not caching the guest user object and is rebuilding it on every request so during registration the data set by CB Core Fields Ajax is just lost since CB Code Field is then building a new guest CBuser object for substitutions.

forge.joomlapolis.com/issues/8796


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.359 seconds

Facebook Twitter LinkedIn