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;