Update on numeric inputs

This commit is contained in:
2024-08-12 11:06:15 +02:00
parent d71a5c25c3
commit 245e76f697
2 changed files with 29 additions and 3 deletions

View File

@@ -146,4 +146,17 @@ export class EditBusinessListingComponent {
changeListingCategory(value: 'business' | 'commercialProperty') {
routeListingWithState(this.router, value, this.listing);
}
onNumericInputChange(value: string, modelProperty: string): void {
const newValue = value === '' ? null : +value;
this.setPropertyByPath(this, modelProperty, newValue);
}
private setPropertyByPath(obj: any, path: string, value: any): void {
const keys = path.split('.');
let target = obj;
for (let i = 0; i < keys.length - 1; i++) {
target = target[keys[i]];
}
target[keys[keys.length - 1]] = value;
}
}