coerce empty string in number/range inputs to undefined - closes #584

pull/606/head
Rich Harris 8 years ago
parent 79d3c44785
commit 6ae01b6682

@ -183,7 +183,7 @@ function getBindingValue ( generator: DomGenerator, block: Block, state: State,
// <input type='range|number' bind:value>
if ( type === 'range' || type === 'number' ) {
return `+${state.parentNode}.${attribute.name}`;
return `${generator.helper( 'toNumber' )}( ${state.parentNode}.${attribute.name} )`;
}
// everything else

@ -60,4 +60,8 @@ export function getBindingGroupValue ( group ) {
if ( group[i].checked ) value.push( group[i].__value );
}
return value;
}
export function toNumber ( value ) {
return value === '' ? undefined : +value;
}

@ -29,5 +29,15 @@ export default {
<input type='number'>
<p>number 44</p>
` );
// empty string should be treated as undefined
input.value = '';
input.dispatchEvent( event );
assert.equal( component.get( 'count' ), undefined );
assert.htmlEqual( target.innerHTML, `
<input type='number'>
<p>undefined undefined</p>
` );
}
};

Loading…
Cancel
Save