This repository was archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Does not work with existing db values #5
Copy link
Copy link
Open
gldrenthe89/nova-calculated-field
#8Description
If the BroadcasterFields have existing values in db.
Those field values are not accounted for when an update form is loaded.
Which makes the User think that the calculation is incorrect.
For better usability it would be best if the initial values of all BroadcasterFields are emitted to the listeners when they are mounted.
Example screen recording
https://www.dropbox.com/s/6izb4h2dxkp8x00/Sk%C3%A4rminspelning%202019-10-14%20kl.%2018.55.21.mov?dl=0
BroadcasterField::make(__('Gross'), 'gross')
->broadcastTo('discount')
->hideFromIndex(),
BroadcasterField::make(__('Disc Percent'), 'disc_percent')
->broadcastTo('discount')
->hideFromIndex(),
BroadcasterField::make(__('Disc Amount'), 'disc_amount')
->broadcastTo('discount')
->hideFromIndex(),
ListenerField::make(__('Discounted Gross'), 'discounted_gross')
->listensTo('discount')
->hideFromIndex()
->calculateWith(function (Collection $values) {
$gross = $values->get('gross');
$disc_percent = $values->get('disc_percent') / 100;
$disc_amount = $values->get('disc_amount');
$disc_sum = ($gross * $disc_percent) + $disc_amount;
$disc_gross = $gross - $disc_sum;
return $disc_gross;
}),
Metadata
Metadata
Assignees
Labels
No labels