diff --git a/src/Model/Entity/MetaTemplateField.php b/src/Model/Entity/MetaTemplateField.php index 570fef9..110f843 100644 --- a/src/Model/Entity/MetaTemplateField.php +++ b/src/Model/Entity/MetaTemplateField.php @@ -25,12 +25,10 @@ class MetaTemplateField extends AppModel $selectOptions = !empty($this->sane_default) ? $this->sane_default : $this->values_list; $selectOptions = array_combine($selectOptions, $selectOptions); if (!empty($this->sane_default)) { - // $selectOptions['_custom'] = __('-- custom value --'); $selectOptions[] = ['value' => '_custom', 'text' => __('-- custom value --'), 'class' => 'custom-value']; } $selectOptions[''] = __('-- no value --'); $formOptions['options'] = $selectOptions; - // $formOptions['empty'] = [['value' => '', 'text' => __('-- select an options --'), 'hidden disabled selected value']]; } return $formOptions; } diff --git a/templates/element/genericElements/Form/Fields/dropdownField.php b/templates/element/genericElements/Form/Fields/dropdownField.php index b8d81b2..b71b15b 100644 --- a/templates/element/genericElements/Form/Fields/dropdownField.php +++ b/templates/element/genericElements/Form/Fields/dropdownField.php @@ -31,10 +31,6 @@ if (in_array('_custom', array_keys($controlParams['options']))) { } else { $customInputValue = ''; } - $customControlParams = [ - 'value' => $fieldData['value'] ?? null, - 'class' => 'd-none', - ]; $controlParams['class'] .= ' dropdown-custom-value' . "-$seed"; $adaptedField = $fieldData['field'] . '_custom'; $controlParams['templates']['formGroup'] = sprintf( @@ -52,17 +48,14 @@ echo $this->FormFieldMassage->prepareFormElement($this->Form, $controlParams, $f toggleFreetextSelectField($select[0]); $select.attr('onclick', 'toggleFreetextSelectField(this)') $select.parent().find('input.custom-value').attr('oninput', 'updateAssociatedSelect(this)') - // updateAssociatedSelect($select.parent().find('input.custom-value')[0]) - - // Multiple saves in dropdown doesn't work - // But multiple saves for custom works but save the first element as `_custom` + updateAssociatedSelect($select.parent().find('input.custom-value')[0]) }) })() function toggleFreetextSelectField(selectEl) { const $select = $(selectEl) - const show = $select.val() == '_custom' + const show = $select.find('option:selected').hasClass('custom-value') const $container = $(selectEl).parent() let $freetextInput = $container.find('input.custom-value') if (show) { diff --git a/templates/element/genericElements/Form/multiFieldButton.php b/templates/element/genericElements/Form/multiFieldButton.php index 9cfd348..ddc17ca 100644 --- a/templates/element/genericElements/Form/multiFieldButton.php +++ b/templates/element/genericElements/Form/multiFieldButton.php @@ -65,9 +65,13 @@ $seed = 'mfb-' . mt_rand(); brackettedPathStr = explodedPath.map((elem, i) => { return i == 0 ? elem : `[${elem}]` }).join('') - $input.attr('id', dottedPathStr) - .attr('field', dottedPathStr) - .attr('name', brackettedPathStr) + const attrs = ['id', 'field', 'name'] + attrs.forEach((attr) => { + if ($input.attr(attr) !== undefined) { + $input.attr(attr, attr === 'name' ? brackettedPathStr : dottedPathStr) + } + }) + $input .val('') .removeClass('is-invalid') }) diff --git a/templates/element/genericElements/Form/multiFieldScaffold.php b/templates/element/genericElements/Form/multiFieldScaffold.php index 89b405c..3099813 100644 --- a/templates/element/genericElements/Form/multiFieldScaffold.php +++ b/templates/element/genericElements/Form/multiFieldScaffold.php @@ -34,7 +34,7 @@ if (!empty($metaFieldsEntities)) { $fieldData['class'] = 'new-metafield'; } if ($labelPrintedOnce) { // Only the first input can have a label - $fieldData['label'] = false; + $fieldData['label'] = ['text' => '']; } if ($metaTemplateField->formType === 'dropdown') { $fieldData = array_merge_recursive($fieldData, $metaTemplateField->formOptions);