Skip to content

Commit 83543b7

Browse files
committed
fix(input): value might be null/undefined
1 parent 2398634 commit 83543b7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

core/src/components/input/input.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class Input {
181181
@Watch('value')
182182
protected valueChanged() {
183183
const inputEl = this.nativeInput;
184-
const value = this.value;
184+
const value = this.getValue();
185185
if (inputEl && inputEl.value !== value) {
186186
inputEl.value = value;
187187
}
@@ -251,6 +251,10 @@ export class Input {
251251
}
252252
}
253253

254+
private getValue(): string {
255+
return this.value || '';
256+
}
257+
254258
private emitStyle() {
255259
this.ionStyle.emit({
256260
'interactive': true,
@@ -313,7 +317,7 @@ export class Input {
313317
}
314318

315319
private hasValue(): boolean {
316-
return this.value.length > 0;
320+
return this.getValue().length > 0;
317321
}
318322

319323
hostData() {
@@ -329,7 +333,7 @@ export class Input {
329333
}
330334

331335
render() {
332-
renderHiddenInput(this.el, this.name, this.value, this.disabled);
336+
renderHiddenInput(this.el, this.name, this.getValue(), this.disabled);
333337

334338
return [
335339
<input
@@ -358,7 +362,7 @@ export class Input {
358362
step={this.step}
359363
size={this.size}
360364
type={this.type}
361-
value={this.value}
365+
value={this.getValue()}
362366
onInput={this.onInput.bind(this)}
363367
onBlur={this.onBlur.bind(this)}
364368
onFocus={this.onFocus.bind(this)}

0 commit comments

Comments
 (0)