File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,16 @@ function EditorForm(props) {
1515 if ( ! ( labelsElement instanceof HTMLSelectElement ) )
1616 return ;
1717 if ( settings . labels ) {
18+ // extract selected values from the original <select multiple name="labels"> element
19+ // this only happens if a user sets a label but the form is rejected by the server
20+ const initial = [ ] ;
21+ for ( const option of labelsElement . selectedOptions ) {
22+ const found = settings . labels . find ( label => label . value == option . value ) ;
23+ if ( found ) {
24+ initial . push ( found ) ;
25+ }
26+ }
27+
1828 // replace the original <select multiple name="labels"> element with the "downshift" component
1929 if ( labelsElement . nextElementSibling ?. classList . contains ( 'select-labels-container' ) ) {
2030 labelsElement . nextElementSibling . remove ( ) ;
@@ -23,7 +33,7 @@ function EditorForm(props) {
2333 divElement . classList . add ( 'select-labels-container' ) ;
2434 labelsElement . insertAdjacentElement ( 'afterend' , divElement ) ;
2535 const root = createRoot ( divElement ) ;
26- root . render ( < SelectLabels labels = { settings . labels } initial = { [ ] } original = { labelsElement } /> ) ;
36+ root . render ( < SelectLabels labels = { settings . labels } initial = { initial } original = { labelsElement } /> ) ;
2737 }
2838 labelsElement . style . display = 'none' ;
2939 } , [ formHtml ] ) ;
You can’t perform that action at this time.
0 commit comments