Skip to content

Commit

Permalink
fix: syncFieldWithNewRow incorrectly replacing row values in field cl…
Browse files Browse the repository at this point in the history
…assName attribute
  • Loading branch information
lucasnetau committed Jul 4, 2024
1 parent c180c9f commit eae8a5f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/js/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down

0 comments on commit eae8a5f

Please sign in to comment.