@@ -1461,6 +1461,8 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
1461
1461
selectElement . setAttribute ( "id" , id ) ;
1462
1462
selectElement . tabIndex = DEFAULT_TAB_INDEX ;
1463
1463
1464
+ let hasAnEmptyEntry = true ;
1465
+
1464
1466
if ( ! this . data . combo ) {
1465
1467
// List boxes have a size and (optionally) multiple selection.
1466
1468
selectElement . size = this . data . options . length ;
@@ -1486,10 +1488,21 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
1486
1488
}
1487
1489
if ( storedData . value . includes ( option . exportValue ) ) {
1488
1490
optionElement . setAttribute ( "selected" , true ) ;
1491
+ hasAnEmptyEntry = false ;
1489
1492
}
1490
1493
selectElement . appendChild ( optionElement ) ;
1491
1494
}
1492
1495
1496
+ if ( hasAnEmptyEntry && this . data . combo && this . data . options ) {
1497
+ const noneOptionElement = document . createElement ( "option" ) ;
1498
+ noneOptionElement . value = " " ;
1499
+ noneOptionElement . setAttribute ( "hidden" , true ) ;
1500
+ selectElement . insertBefore ( noneOptionElement , selectElement . firstChild ) ;
1501
+ noneOptionElement . setAttribute ( "selected" , true ) ;
1502
+ } else {
1503
+ hasAnEmptyEntry = false ;
1504
+ }
1505
+
1493
1506
const getValue = ( event , isExport ) => {
1494
1507
const name = isExport ? "value" : "textContent" ;
1495
1508
const options = event . target . options ;
@@ -1602,6 +1615,10 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
1602
1615
} ) ;
1603
1616
1604
1617
selectElement . addEventListener ( "input" , event => {
1618
+ if ( hasAnEmptyEntry ) {
1619
+ selectElement . firstChild . remove ( ) ;
1620
+ hasAnEmptyEntry = false ;
1621
+ }
1605
1622
const exportValue = getValue ( event , /* isExport */ true ) ;
1606
1623
const value = getValue ( event , /* isExport */ false ) ;
1607
1624
storage . setValue ( id , { value : exportValue } ) ;
0 commit comments