⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Calculated Values



dwdc
  • profile picture
  • Member

Posted 28 February 2014 - 07:51 AM

Is there a way to add rows to GC ADD and EDIT forms that are simply calculations of fields in the target table (not actual fields)?

For example: Let's say I have the following real fields in my table:

low_bid
high_bid

winning_bid

I want to have a few values that are simply READ ONLY values that RE-CALC when related field values are modified:

low_bid_50p = (low_bid * .5)
high_bid_50p = (high_bid * .5)
agent_fee = if((winning_bid *.065) < 1750 THEN 1750 ELSE (winning_bid *.065))

I can do this easy enough in RAW PHP/mySQL along with javascript to make sure values re-calculate when user adds/modifies values at the data entry level. Was wondering if anyone has pulled this off in GC.

Any help would be appreciated. Thanks!


 

 


connard
  • profile picture
  • Member

Posted 01 March 2014 - 00:24 AM

yeah with callback_add_field, and you run your own calc function in it and return the value


Amit Shah
  • profile picture
  • Member

Posted 01 March 2014 - 08:28 AM

brother, i believe the solution to the same was already provided. You have to use it the way it was described. Dont thing every single bit of code will be developed for u for your logic that you could copy paste... As suggested by connard and also in my earlier reply - yes u have to use callback_add_field.. and also use javascript both in conjunction to derive to the desired solution


dwdc
  • profile picture
  • Member

Posted 04 March 2014 - 21:43 PM

Thank you Amit and Conrad, but i am confused on how to reference other cells in the ROW array. Based of the following function:
 

$crud->callback_edit_field('low_bid_50p',array($this,'edit_field_low_bid_50p'));

Then I would like the function to do the following:



function edit_field_low_bid_50p($value, $primary_key)
{

$value = ($row->low_bid * .5); // this is another fields value

return '<div id="field-cagent_fee_5p" class="readonly_label">'.$value.'</div>';
}

 


Once I understand how the values are passed into this function (and if other values can be included), I can then handle the additional javascript calls to make these values change when user in modify input in form.

Thanks for your patience.

 

Don


Amit Shah
  • profile picture
  • Member

Posted 04 March 2014 - 22:10 PM

u have to do it using the javascript.. u can add the custom script using set_js


dwdc
  • profile picture
  • Member

Posted 05 March 2014 - 03:54 AM

Ahhh - I am glad you clarified this. I will look into that function. Thanks!

 

Don