Skip to content

Commit

Permalink
fix: stopIndex is incorrectly calculated when in enhancedBootstrap mo…
Browse files Browse the repository at this point in the history
…de. Fix this by always referring to children of the stage rather than LIs
  • Loading branch information
lucasnetau committed Oct 13, 2023
1 parent d7cdc34 commit 052a761
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/js/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function FormBuilder(opts, element, $) {
}

const $control = $(target).closest('li')
h.stopIndex = opts.append ? $stage.children('li').length - 1 : undefined
h.stopIndex = opts.append ? $stage.children().length - 1 : undefined
processControl($control)
h.save.call(h)
})
Expand Down Expand Up @@ -1151,7 +1151,7 @@ function FormBuilder(opts, element, $) {
$li.data('fieldData', { attrs: values })

if (typeof h.stopIndex !== 'undefined') {
$('> li', d.stage).eq(h.stopIndex).before($li)
$(d.stage).children().eq(h.stopIndex).before($li)
} else {
$stage.append($li)
}
Expand Down
3 changes: 2 additions & 1 deletion src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export default class Helpers {
const form = _this.d.stage
const lastIndex = form.childNodes.length - 1
const cancelArray = []
_this.stopIndex = ui.placeholder.index() - 1
//Find the index within the stage even if the placeholder is not a direct descendant
_this.stopIndex = ui.placeholder.closest('ul.stage-wrap > *').index() - 1

if (!opts.sortableControls && ui.item.parent().hasClass('frmb-control')) {
cancelArray.push(true)
Expand Down

0 comments on commit 052a761

Please sign in to comment.