Skip to content

Commit a2561da

Browse files
committed
remember labels in Browser Editor when submitting a form which does not validater
1 parent 6489f17 commit a2561da

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

client/browser/BrowserEditor.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff 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]);

0 commit comments

Comments
 (0)