From b48f7bcb8d09dd51a14cfce7dbb36dd043e350b7 Mon Sep 17 00:00:00 2001 From: Marc Laval Date: Fri, 29 Jul 2016 15:53:22 +0200 Subject: [PATCH] fix(forms): normalize written value in NumberValueAccessor Closes #10379 --- .../forms-deprecated/directives/number_value_accessor.ts | 6 ++++-- .../@angular/forms/src/directives/number_value_accessor.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/@angular/common/src/forms-deprecated/directives/number_value_accessor.ts b/modules/@angular/common/src/forms-deprecated/directives/number_value_accessor.ts index 7d654eaf24..cba506a9ef 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/number_value_accessor.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/number_value_accessor.ts @@ -8,7 +8,7 @@ import {Directive, ElementRef, Renderer, forwardRef} from '@angular/core'; -import {NumberWrapper} from '../../facade/lang'; +import {NumberWrapper, isBlank} from '../../facade/lang'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; @@ -44,7 +44,9 @@ export class NumberValueAccessor implements ControlValueAccessor { constructor(private _renderer: Renderer, private _elementRef: ElementRef) {} writeValue(value: number): void { - this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', value); + // The value needs to be normalized for IE9, otherwise it is set to 'null' when null + const normalizedValue = isBlank(value) ? '' : value; + this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', normalizedValue); } registerOnChange(fn: (_: number) => void): void { diff --git a/modules/@angular/forms/src/directives/number_value_accessor.ts b/modules/@angular/forms/src/directives/number_value_accessor.ts index 3583019086..112ba8f059 100644 --- a/modules/@angular/forms/src/directives/number_value_accessor.ts +++ b/modules/@angular/forms/src/directives/number_value_accessor.ts @@ -8,7 +8,7 @@ import {Directive, ElementRef, Renderer, forwardRef} from '@angular/core'; -import {NumberWrapper} from '../facade/lang'; +import {NumberWrapper, isBlank} from '../facade/lang'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; @@ -44,7 +44,9 @@ export class NumberValueAccessor implements ControlValueAccessor { constructor(private _renderer: Renderer, private _elementRef: ElementRef) {} writeValue(value: number): void { - this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', value); + // The value needs to be normalized for IE9, otherwise it is set to 'null' when null + const normalizedValue = isBlank(value) ? '' : value; + this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', normalizedValue); } registerOnChange(fn: (_: number) => void): void {