From 5b0ffeb8c5c72c16e11d00725a17b93d9ceeb336 Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Tue, 7 Jan 2020 17:23:34 +0100 Subject: [PATCH] Preselect value in select [MAILPOET-2592] --- .../form_editor/blocks/custom_select/edit.jsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/assets/js/src/form_editor/blocks/custom_select/edit.jsx b/assets/js/src/form_editor/blocks/custom_select/edit.jsx index ff9afa4bb2..0394abb43c 100644 --- a/assets/js/src/form_editor/blocks/custom_select/edit.jsx +++ b/assets/js/src/form_editor/blocks/custom_select/edit.jsx @@ -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 ( - { options.map((option) => (