From f5a361a96452b5940044923de8521b029b5a3d83 Mon Sep 17 00:00:00 2001 From: James Lucas Date: Tue, 12 Mar 2024 10:40:37 +1100 Subject: [PATCH] fix: restoring value of typeUserAttr select with attributeName className --- src/js/form-builder.js | 6 ++-- tests/form-builder.test.js | 72 +++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/js/form-builder.js b/src/js/form-builder.js index a174f6bfa..f242756cc 100644 --- a/src/js/form-builder.js +++ b/src/js/form-builder.js @@ -784,14 +784,14 @@ function FormBuilder(opts, element, $) { */ function selectUserAttrs(name, fieldData) { const { multiple, options, label: labelText, value, class: classname, className, ...restData } = fieldData + const selectValues = fieldData.hasOwnProperty(name) ? fieldData[name] : value || [] const optis = Object.keys(options).map(val => { const attrs = { value: val } const optionTextVal = options[val] const optionText = Array.isArray(optionTextVal) ? mi18n.get(...optionTextVal) || optionTextVal[0] : optionTextVal - if (Array.isArray(value) ? value.includes(val) : val === value) { - attrs.selected = null + if (Array.isArray(selectValues) ? selectValues.includes(val) : val === selectValues) { + attrs.selected = true } - return m('option', optionText, attrs) }) diff --git a/tests/form-builder.test.js b/tests/form-builder.test.js index 4c78ec16f..45457d511 100644 --- a/tests/form-builder.test.js +++ b/tests/form-builder.test.js @@ -485,15 +485,15 @@ describe('FormBuilder typeUserAttrs detection', () => { typeUserAttrs: { '*': { testSelectAttribute: { - label: 'Class', // i18n support by passing and array eg. ['optionCount', {count: 3}] - multiple: true, // optional, omitting generates normal