@@ -436,32 +436,36 @@ class ComboboxView extends TextView {
436
436
update ( options ?: any ) {
437
437
super . update ( options ) ;
438
438
if ( ! this . datalist ) {
439
- return ;
439
+ return ;
440
440
}
441
441
442
442
const valid = this . isValid ( this . model . get ( 'value' ) ) ;
443
443
this . highlightValidState ( valid ) ;
444
444
445
445
// Check if we need to update options
446
- if ( options !== undefined && options . updated_view ) {
447
- // Value update only, keep current options
448
- return ;
446
+ if ( ( options !== undefined && options . updated_view ) || (
447
+ ! this . model . hasChanged ( 'options' ) &&
448
+ ! this . isInitialRender
449
+ ) ) {
450
+ // Value update only, keep current options
451
+ return ;
449
452
}
450
453
451
- this . datalist . innerHTML = '' ;
452
- for ( let opt of this . model . get ( 'options' ) as string [ ] ) {
453
- let el = document . createElement ( 'option' ) ;
454
- el . value = opt ;
455
- this . datalist . appendChild ( el ) ;
456
- }
454
+ this . isInitialRender = false ;
455
+
456
+ const opts = this . model . get ( 'options' ) as string [ ] ;
457
+ const optLines = opts . map ( o => {
458
+ return `<option value="${ o } "></option>` ;
459
+ } ) ;
460
+ this . datalist . innerHTML = optLines . join ( '\n' ) ;
457
461
}
458
462
459
463
isValid ( value : string ) : boolean {
460
464
if ( true === this . model . get ( 'ensure_option' ) ) {
461
- const options = this . model . get ( 'options' ) as string [ ] ;
462
- if ( options . indexOf ( value ) === - 1 ) {
463
- return false ;
464
- }
465
+ const options = this . model . get ( 'options' ) as string [ ] ;
466
+ if ( options . indexOf ( value ) === - 1 ) {
467
+ return false ;
468
+ }
465
469
}
466
470
return true ;
467
471
}
@@ -472,7 +476,7 @@ class ComboboxView extends TextView {
472
476
const valid = this . isValid ( target . value ) ;
473
477
this . highlightValidState ( valid ) ;
474
478
if ( valid ) {
475
- super . handleChanging ( e ) ;
479
+ super . handleChanging ( e ) ;
476
480
}
477
481
}
478
482
@@ -482,7 +486,7 @@ class ComboboxView extends TextView {
482
486
const valid = this . isValid ( target . value ) ;
483
487
this . highlightValidState ( valid ) ;
484
488
if ( valid ) {
485
- super . handleChanged ( e ) ;
489
+ super . handleChanged ( e ) ;
486
490
}
487
491
}
488
492
@@ -491,4 +495,6 @@ class ComboboxView extends TextView {
491
495
}
492
496
493
497
datalist : HTMLDataListElement | undefined ;
498
+
499
+ isInitialRender = true ;
494
500
}
0 commit comments