Preselect value in select

[MAILPOET-2592]
This commit is contained in:
Pavel Dohnal
2020-01-07 17:23:34 +01:00
committed by Rostislav Wolný
parent e4cae403ad
commit 5b0ffeb8c5

View File

@@ -66,16 +66,24 @@ const CustomSelectEdit = ({ attributes, setAttributes, clientId }) => {
);
const getInput = () => {
let defaultValue = attributes.labelWithinInput ? formatLabel(attributes) : '-';
const options = [{
label: attributes.labelWithinInput ? formatLabel(attributes) : '-',
label: defaultValue,
}];
if (Array.isArray(attributes.values) || !attributes.values.length) {
attributes.values.forEach((value) => options.push({
label: value.name,
}));
attributes.values.forEach((value) => {
options.push({
label: value.name,
});
if (!attributes.labelWithinInput && value.isChecked) {
defaultValue = value.name;
}
});
}
return (
<select className="mailpoet_select" id={clientId}>
<select className="mailpoet_select" id={clientId} value={defaultValue}>
{
options.map((option) => (
<option key={option.label} value={option.label}>