fix: [metafields:dropdown] Patched saving multiple fields with custom value
parent
b53f2681b4
commit
1d6187198f
|
@ -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) {
|
||||
|
|
|
@ -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')
|
||||
})
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue