Skip to content

Commit

Permalink
SHIBUI-1693 Fixed issue with decimals in firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Dec 9, 2019
1 parent 27c117d commit 72b7107
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions ui/src/app/schema-form/widget/number/float.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,11 @@ export class CustomFloatComponent extends IntegerWidget implements AfterViewInit
}

ngAfterViewInit() {
super.ngAfterViewInit();
const control = this.control;
this.formProperty.valueChanges.subscribe((newValue) => {
if (typeof this._displayValue !== 'undefined') {
// Ignore the model value, use the display value instead
if (control.value !== this._displayValue) {
control.setValue(this._displayValue, { emitEvent: false });
}
} else {
if (control.value !== newValue) {
control.setValue(newValue, { emitEvent: false });
}
}
});

if (this.formProperty.value) {
control.setValue(this.formProperty.value, { emitEvent: false });
}
this.formProperty.errorsChanges.subscribe((errors) => {
control.setErrors(errors, { emitEvent: true });
const messages = (errors || [])
Expand All @@ -46,13 +37,15 @@ export class CustomFloatComponent extends IntegerWidget implements AfterViewInit
control.valueChanges.subscribe((newValue) => {
const native = (<HTMLInputElement>this.element.nativeElement);
this._displayValue = newValue;
this.formProperty.setValue(newValue, false);
if (newValue === '' && native.validity.badInput) {
this.formProperty.setValue(native.valueAsNumber, false);
this.formProperty.extendErrors([{
code: 'INVALID_NUMBER',
path: `#${this.formProperty.path}`,
message: 'Invalid number',
}]);
} else {
this.formProperty.setValue(newValue, false);
}
});
}
Expand Down

0 comments on commit 72b7107

Please sign in to comment.