Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap feature updates #1482

Merged
merged 6 commits into from
Nov 7, 2023
86 changes: 29 additions & 57 deletions src/js/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,8 @@ function FormBuilder(opts, element, $) {

const type = values.type || 'text'
let label = values.label || (isNew ? i18n[type] || mi18n.get('label') : '')
if (type === 'hidden') {
label = `${mi18n.get(type)}: ${values.name}`
if (type === 'hidden' || label === '') {
label = `${mi18n.get(type) ?? type}: ${values.name}`
}
const disabledFieldButtons = opts.disabledFieldButtons[type] || values.disabledFieldButtons
let fieldButtons = [
Expand Down Expand Up @@ -1148,6 +1148,7 @@ function FormBuilder(opts, element, $) {
$targetInsertWrapper.attr('id', rowWrapperNode.id)
$targetInsertWrapper.attr('class', rowWrapperNode.className)
$targetInsertWrapper.attr('style', '')
$targetInsertWrapper.attr('data-row-id', columnData.rowUniqueId)
rowWrapperNode = $targetInsertWrapper
}

Expand Down Expand Up @@ -1316,34 +1317,32 @@ function FormBuilder(opts, element, $) {
const senderIsControlsBox = $(ui.sender).attr('id') === $cbUL.attr('id')

const droppingToNewRow = $(ui.item).parent().hasClass(tmpRowPlaceholderClass)
const droppingToPlaceholderRow = $(ui.item).parent().hasClass(tmpRowPlaceholderClass)
const droppingToExistingRow =
$(ui.item).parent().hasClass(rowWrapperClass) && !$(ui.item).parent().hasClass(tmpRowPlaceholderClass)
const droppingToExistingRow = !droppingToNewRow && $(ui.item).parent().hasClass(rowWrapperClass)

if (droppingToNewRow && !senderIsControlsBox) {
const colWrapper = $(ui.item)

const columnData = prepareFieldRow({})
if (droppingToNewRow) {
if (senderIsControlsBox) {
insertTargetIsRow = true
insertingNewControl = true
$targetInsertWrapper = $(ui.item).parent()
} else {
const colWrapper = $(ui.item)

const rowWrapperNode = m('div', null, {
id: `${colWrapper.find('li').attr('id')}-row`,
className: `row row-${columnData.rowUniqueId} ${rowWrapperClass}`,
})
const columnData = prepareFieldRow({})

$(ui.item).parent().replaceWith(rowWrapperNode)
AttachColWrapperHandler($(ui.item))
const rowWrapperNode = m('div', null, {
id: `${colWrapper.find('li').attr('id')}-row`,
className: `row row-${columnData.rowUniqueId} ${rowWrapperClass}`,
})

colWrapper.appendTo(rowWrapperNode)
$(ui.item).parent().replaceWith(rowWrapperNode)
AttachColWrapperHandler($(ui.item))

setupSortableRowWrapper(rowWrapperNode)
syncFieldWithNewRow(colWrapper.attr('id'))
checkRowCleanup()
}
colWrapper.appendTo(rowWrapperNode)

if (droppingToPlaceholderRow && senderIsControlsBox) {
insertTargetIsRow = true
insertingNewControl = true
$targetInsertWrapper = $(ui.item).parent()
setupSortableRowWrapper(rowWrapperNode)
syncFieldWithNewRow(colWrapper.attr('id'))
checkRowCleanup()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this if its called below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. I've removed the redundant checkRowCleanup() here

}
}

if (droppingToExistingRow && senderIsControlsBox) {
Expand Down Expand Up @@ -1371,6 +1370,7 @@ function FormBuilder(opts, element, $) {
h.save.call(h)
}

checkRowCleanup()
ResetAllInvisibleRowPlaceholders()

const listFieldItem = $(ui.item).find('li')
Expand All @@ -1394,6 +1394,11 @@ function FormBuilder(opts, element, $) {
},
})

const rowId = h.getRowValue(rowWrapperNode.className)
if (rowId !== '0') {
$(rowWrapperNode).attr('data-row-id',rowId)
}

setupColumnInserts(rowWrapperNode, true)
if (opts.enableColumnInsertMenu) {
$(rowWrapperNode).off('mouseenter')
Expand Down Expand Up @@ -1846,7 +1851,6 @@ function FormBuilder(opts, element, $) {
if (enhancedBootstrapEnabled()) {
$stage.on('stageEmptied', () => {
formRows = [] //Reset row count
checkSetupBlankStage()
})
}

Expand Down Expand Up @@ -2116,8 +2120,6 @@ function FormBuilder(opts, element, $) {
if (rowWrapper.length) {
autoSizeRowColumns(rowWrapper, true)
}

checkSetupBlankStage()
})

$(document).on('fieldOpened', (event, data) => {
Expand Down Expand Up @@ -2154,33 +2156,6 @@ function FormBuilder(opts, element, $) {
})
}

/**
* enhancedBootstrap feature helper
*/
function checkSetupBlankStage() {
if (!(enhancedBootstrapEnabled() && h.stageIsEmpty())) {
return
}

const columnData = prepareFieldRow({})

const rowWrapperNode = m('div', null, {
id: `${h.incrementId(data.lastID)}-row`,
className: `row row-${columnData.rowUniqueId} ${rowWrapperClass}`,
})

$stage.append(rowWrapperNode)
setupSortableRowWrapper(rowWrapperNode)
ResetAllInvisibleRowPlaceholders()

//Create 1 invisible placeholder which will allow the initial drag anywhere in the stage
$stage
.find(tmpRowPlaceholderClassSelector)
.eq(0)
.removeClass(invisibleRowPlaceholderClass)
.css({ backgroundColor: 'transparent' })
}

function toggleGridModeActive(active = true) {
if (active) {
gridMode = true
Expand Down Expand Up @@ -2472,9 +2447,6 @@ function FormBuilder(opts, element, $) {
if (opts.stickyControls.enable) {
h.stickyControls($stage)
}

checkSetupBlankStage()

clearTimeout(onRenderTimeout)
}, 0)
})
Expand Down