Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Does not work with existing db values #5

Open
tanthammar opened this issue Oct 14, 2019 · 3 comments · Fixed by gldrenthe89/nova-calculated-field#8
Open

Does not work with existing db values #5

tanthammar opened this issue Oct 14, 2019 · 3 comments · Fixed by gldrenthe89/nova-calculated-field#8

Comments

@tanthammar
Copy link

tanthammar commented Oct 14, 2019

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;
}),
@ramisaaa
Copy link

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?

@tanthammar
Copy link
Author

@ramisaaa No, I did not.

@alexander-code
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants