From bb21d74cbf3c2f426631a0ca9f767bf811b8b492 Mon Sep 17 00:00:00 2001 From: Chad Hietala Date: Mon, 19 Jun 2017 18:43:28 -0700 Subject: [PATCH] Fix IE null value serialization --- .../@glimmer/runtime/lib/vm/attributes/dynamic.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts b/packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts index d8a9603e2f..92700e0b19 100644 --- a/packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts +++ b/packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts @@ -126,13 +126,13 @@ export class SafeDynamicProperty extends DefaultDynamicProperty { export class InputValueDynamicAttribute extends DefaultDynamicProperty { set(dom: ElementBuilder, value: Opaque) { - dom.__setProperty('value', normalizeStringValue(value)); + dom.__setProperty('value', normalizeInputValue(value)); } update(value: Opaque) { let input = this.attribute.element; let currentValue = input.value; - let normalizedValue = normalizeStringValue(value); + let normalizedValue = normalizeInputValue(value); if (currentValue !== normalizedValue) { input.value = normalizedValue!; } @@ -165,6 +165,14 @@ function isUserInputValue(tagName: string, attribute: string) { return (tagName === 'INPUT' || tagName === 'TEXTAREA') && attribute === 'value'; } +function normalizeInputValue(value: Opaque) { + if (value === null || value === undefined || typeof value.toString !== 'function') { + return ''; + } + + return `${value}`; +} + function normalizeStringValue(value: Opaque): Option { if (value === false || value === undefined || value === null || typeof value.toString === 'undefined') { return null;