7953e better form editor (#580)
* Form editor v2 * fix template test * setFormDefaults when save * fix form cleaning dark mode * improvements on open sidebar * UI polish * Fix change type button * Ability to drag & add multiple form blocks --------- Co-authored-by: Chirag Chhatrala <chirag.chhatrala@gmail.com>
This commit is contained in:
parent
d6181cd249
commit
5dcd4ff8cb
|
|
@ -551,7 +551,7 @@ export default {
|
||||||
handleDragDropped(data) {
|
handleDragDropped(data) {
|
||||||
if (data.added) {
|
if (data.added) {
|
||||||
const targetIndex = this.getTargetFieldIndex(data.added.newIndex)
|
const targetIndex = this.getTargetFieldIndex(data.added.newIndex)
|
||||||
this.workingFormStore.addBlock(data.added.element, targetIndex)
|
this.workingFormStore.addBlock(data.added.element, targetIndex, false)
|
||||||
}
|
}
|
||||||
if (data.moved) {
|
if (data.moved) {
|
||||||
const oldTargetIndex = this.getTargetFieldIndex(data.moved.oldIndex)
|
const oldTargetIndex = this.getTargetFieldIndex(data.moved.oldIndex)
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ export const useWorkingFormStore = defineStore("working_form", {
|
||||||
return data
|
return data
|
||||||
},
|
},
|
||||||
|
|
||||||
addBlock(type, index = null) {
|
addBlock(type, index = null, openSettings = true) {
|
||||||
this.blockForm.type = type
|
this.blockForm.type = type
|
||||||
this.blockForm.name = blocksTypes[type].default_block_name
|
this.blockForm.name = blocksTypes[type].default_block_name
|
||||||
const newBlock = this.prefillDefault(this.blockForm.data())
|
const newBlock = this.prefillDefault(this.blockForm.data())
|
||||||
|
|
@ -117,15 +117,39 @@ export const useWorkingFormStore = defineStore("working_form", {
|
||||||
const newFields = clonedeep(this.content.properties)
|
const newFields = clonedeep(this.content.properties)
|
||||||
newFields.push(newBlock)
|
newFields.push(newBlock)
|
||||||
this.content.properties = newFields
|
this.content.properties = newFields
|
||||||
this.openSettingsForField(
|
if (openSettings) {
|
||||||
this.content.properties.length - 1,
|
this.openSettingsForField(
|
||||||
)
|
this.content.properties.length - 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const fieldIndex = typeof index === "number" ? index : this.selectedFieldIndex + 1
|
const fieldIndex = typeof index === "number" ? index : this.selectedFieldIndex + 1
|
||||||
const newFields = clonedeep(this.content.properties)
|
const newFields = clonedeep(this.content.properties)
|
||||||
newFields.splice(fieldIndex, 0, newBlock)
|
newFields.splice(fieldIndex, 0, newBlock)
|
||||||
this.content.properties = newFields
|
this.content.properties = newFields
|
||||||
this.openSettingsForField(fieldIndex)
|
if (openSettings) {
|
||||||
|
this.openSettingsForField(fieldIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeField(field) {
|
||||||
|
this.internalRemoveField(field)
|
||||||
|
},
|
||||||
|
internalRemoveField(field) {
|
||||||
|
const index = this.objectToIndex(field)
|
||||||
|
|
||||||
|
if (index !== -1) {
|
||||||
|
useAlert().success('Ctrl + Z to undo',10000,{
|
||||||
|
title: 'Field removed',
|
||||||
|
actions: [{
|
||||||
|
label: 'Undo',
|
||||||
|
icon:"i-material-symbols-undo",
|
||||||
|
click: () => {
|
||||||
|
this.undo()
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
this.content.properties.splice(index, 1)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
removeField(field) {
|
removeField(field) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue