Skip to content

Commit

Permalink
Fix IE null value serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhietala committed Jun 20, 2017
1 parent 9c690dd commit bb21d74
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <HTMLInputElement>this.attribute.element;
let currentValue = input.value;
let normalizedValue = normalizeStringValue(value);
let normalizedValue = normalizeInputValue(value);
if (currentValue !== normalizedValue) {
input.value = normalizedValue!;
}
Expand Down Expand Up @@ -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<string> {
if (value === false || value === undefined || value === null || typeof value.toString === 'undefined') {
return null;
Expand Down

0 comments on commit bb21d74

Please sign in to comment.