Preselect value in select
[MAILPOET-2592]
This commit is contained in:
committed by
Rostislav Wolný
parent
e4cae403ad
commit
5b0ffeb8c5
@@ -66,16 +66,24 @@ const CustomSelectEdit = ({ attributes, setAttributes, clientId }) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const getInput = () => {
|
const getInput = () => {
|
||||||
|
let defaultValue = attributes.labelWithinInput ? formatLabel(attributes) : '-';
|
||||||
const options = [{
|
const options = [{
|
||||||
label: attributes.labelWithinInput ? formatLabel(attributes) : '-',
|
label: defaultValue,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
if (Array.isArray(attributes.values) || !attributes.values.length) {
|
if (Array.isArray(attributes.values) || !attributes.values.length) {
|
||||||
attributes.values.forEach((value) => options.push({
|
attributes.values.forEach((value) => {
|
||||||
label: value.name,
|
options.push({
|
||||||
}));
|
label: value.name,
|
||||||
|
});
|
||||||
|
if (!attributes.labelWithinInput && value.isChecked) {
|
||||||
|
defaultValue = value.name;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<select className="mailpoet_select" id={clientId}>
|
<select className="mailpoet_select" id={clientId} value={defaultValue}>
|
||||||
{
|
{
|
||||||
options.map((option) => (
|
options.map((option) => (
|
||||||
<option key={option.label} value={option.label}>
|
<option key={option.label} value={option.label}>
|
||||||
|
Reference in New Issue
Block a user