Fix #478 - currency losing format after conversion

This commit is contained in:
Jack Anderson 2024-08-07 16:03:02 +01:00 committed by y.yerli
parent 2c5861e9cb
commit b145a923c4

View file

@ -31,6 +31,7 @@ import {Record} from '../../../common/record/record.model';
import {ViewMode} from '../../../common/views/view.model'; import {ViewMode} from '../../../common/views/view.model';
import {FieldLogicActionData, FieldLogicActionHandler} from '../field-logic.action'; import {FieldLogicActionData, FieldLogicActionHandler} from '../field-logic.action';
import {CurrencyService} from '../../../services/currency/currency.service'; import {CurrencyService} from '../../../services/currency/currency.service';
import {CurrencyFormatter} from "../../../services/formatters/currency/currency-formatter.service";
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -40,7 +41,7 @@ export class UpdateCurrencyAction extends FieldLogicActionHandler {
key = 'update-currency'; key = 'update-currency';
modes = ['edit', 'create', 'massupdate', 'filter'] as ViewMode[]; modes = ['edit', 'create', 'massupdate', 'filter'] as ViewMode[];
constructor(protected currencyService: CurrencyService) { constructor(protected currencyService: CurrencyService, protected currencyFormatter: CurrencyFormatter) {
super(); super();
} }
@ -74,8 +75,12 @@ export class UpdateCurrencyAction extends FieldLogicActionHandler {
} }
protected updateValue(field: Field, value: number, record: Record): void { protected updateValue(field: Field, value: number, record: Record): void {
field.value = value.toString(); const options = {
field.formControl.setValue(value.toString()); mode: 'edit' as ViewMode
}
const formattedValue = this.currencyFormatter.toUserFormat(value.toString(), options)
field.value = formattedValue;
field.formControl.setValue(formattedValue);
// re-validate the parent form-control after value update // re-validate the parent form-control after value update
record.formGroup.updateValueAndValidity({onlySelf: true, emitEvent: true}); record.formGroup.updateValueAndValidity({onlySelf: true, emitEvent: true});
} }