From eae8a5f146feceeff09b4a0eed999891dc357dce Mon Sep 17 00:00:00 2001 From: James Lucas Date: Thu, 4 Jul 2024 12:51:48 +1000 Subject: [PATCH] fix: syncFieldWithNewRow incorrectly replacing row values in field className attribute --- src/js/form-builder.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/js/form-builder.js b/src/js/form-builder.js index b44a5c0b1..355e7212f 100644 --- a/src/js/form-builder.js +++ b/src/js/form-builder.js @@ -2139,13 +2139,27 @@ function FormBuilder(opts, element, $) { }) } + /** + * Updates the field's className to include the current wrapping row, removing the previous row if defined + * @param fieldID + */ function syncFieldWithNewRow(fieldID) { if (fieldID) { const inputClassElement = $(`#className-${fieldID.replace('-cont', '')}`) - if (inputClassElement.val()) { - const oldRow = h.getRowClass(inputClassElement.val()) + const currentClassName = inputClassElement.val().trim() + if (currentClassName) { + let currentClasses = currentClassName.split(' ') + const oldRow = h.getRowClass(currentClassName) const wrapperRow = h.getRowClass(inputClassElement.closest(rowWrapperClassSelector).attr('class')) - inputClassElement.val(inputClassElement.val().replace(oldRow, wrapperRow)) + if (oldRow !== wrapperRow) { + if (oldRow) { + currentClasses = currentClasses.filter(function(obj) { + return obj !== oldRow + }) + } + currentClasses.push(wrapperRow) + inputClassElement.val(currentClasses.join(' ')) + } checkRowCleanup() } }