fix(input): value might be null/undefined

This commit is contained in:
Manu Mtz.-Almeida
2018-09-12 20:54:18 +02:00
parent 239863465c
commit 83543b727b

View File

@ -181,7 +181,7 @@ export class Input {
@Watch('value') @Watch('value')
protected valueChanged() { protected valueChanged() {
const inputEl = this.nativeInput; const inputEl = this.nativeInput;
const value = this.value; const value = this.getValue();
if (inputEl && inputEl.value !== value) { if (inputEl && inputEl.value !== value) {
inputEl.value = value; inputEl.value = value;
} }
@ -251,6 +251,10 @@ export class Input {
} }
} }
private getValue(): string {
return this.value || '';
}
private emitStyle() { private emitStyle() {
this.ionStyle.emit({ this.ionStyle.emit({
'interactive': true, 'interactive': true,
@ -313,7 +317,7 @@ export class Input {
} }
private hasValue(): boolean { private hasValue(): boolean {
return this.value.length > 0; return this.getValue().length > 0;
} }
hostData() { hostData() {
@ -329,7 +333,7 @@ export class Input {
} }
render() { render() {
renderHiddenInput(this.el, this.name, this.value, this.disabled); renderHiddenInput(this.el, this.name, this.getValue(), this.disabled);
return [ return [
<input <input
@ -358,7 +362,7 @@ export class Input {
step={this.step} step={this.step}
size={this.size} size={this.size}
type={this.type} type={this.type}
value={this.value} value={this.getValue()}
onInput={this.onInput.bind(this)} onInput={this.onInput.bind(this)}
onBlur={this.onBlur.bind(this)} onBlur={this.onBlur.bind(this)}
onFocus={this.onFocus.bind(this)} onFocus={this.onFocus.bind(this)}