Does not work with existing db values
tanthammar opened this issue · comments
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;
}),
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=0BroadcasterField::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; }),
hi,did you find any solution for this?
Hi, any news about that?
@codebykyle This is a really nice component, seems that is abandoned, would be great to solve this issue so this component will become more useful.