calculated-field icon indicating copy to clipboard operation
calculated-field copied to clipboard

Does not work with existing db values

Open tanthammar opened this issue 6 years ago • 3 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;
}),

tanthammar avatar Oct 14 '19 16:10 tanthammar

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;
}),

hi,did you find any solution for this?

ramisaaa avatar Nov 13 '19 12:11 ramisaaa

@ramisaaa No, I did not.

tanthammar avatar Dec 13 '19 12:12 tanthammar

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.

alexander-code avatar Oct 05 '21 10:10 alexander-code