Skip to content

Commit

Permalink
fix(demo): clear current id when removed from stage
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchappell committed Jan 26, 2020
1 parent fd6966f commit e0c0f2e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/demo/js/actionButtons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { titleCase } from './utils'

export const setCurrentFieldIdValues = value => {
const currentFieldIds = document.querySelectorAll('.current-field-id')
currentFieldIds.forEach(field => {
field.value = value
})
}

export const builderActions = {
showData: () => $('.build-wrap').formBuilder('showData'),
clearFields: () => $('.build-wrap').formBuilder('clearFields'),
Expand All @@ -21,6 +28,7 @@ export const builderActions = {
},
removeField: () => {
const currentFieldId = $('.build-wrap').formBuilder('getCurrentFieldId')
setCurrentFieldIdValues('')
$('.build-wrap').formBuilder('removeField', currentFieldId)
},
getXML: () => {
Expand Down
7 changes: 2 additions & 5 deletions src/demo/js/demo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../sass/demo.scss'
import { insertStyle, removeStyle } from '../../js/utils'
import { demoActions, generateActionTable } from './actionButtons'
import { demoActions, generateActionTable, setCurrentFieldIdValues } from './actionButtons'

const localeSessionKey = 'formBuilder-locale'
const defaultLocale = 'en-US'
Expand Down Expand Up @@ -211,10 +211,7 @@ jQuery(function($) {
},
onSave: toggleEdit,
onAddField: fieldId => {
const currentFieldIds = document.querySelectorAll('.current-field-id')
currentFieldIds.forEach(field => {
field.value = fieldId
})
setCurrentFieldIdValues(fieldId)
},
onClearAll: () => window.sessionStorage.removeItem('formData'),
stickyControls: {
Expand Down
8 changes: 4 additions & 4 deletions src/js/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,9 @@ const FormBuilder = function(opts, element, $) {
})

// Copy field
$stage.on('click touchstart', '.icon-copy', function(e) {
e.preventDefault()
const currentItem = $(e.target)
$stage.on('click touchstart', '.icon-copy', function(evt) {
evt.preventDefault()
const currentItem = $(evt.target)
.parent()
.parent('li')
const $clone = cloneItem(currentItem)
Expand Down Expand Up @@ -1257,7 +1257,7 @@ const FormBuilder = function(opts, element, $) {
h.confirm([warnH3, warnMessage], () => h.removeField(deleteID), coords)
$field.addClass('deleting')
} else {
h.removeField(deleteID)
h.removeField(deleteID, e)
}
})

Expand Down
5 changes: 3 additions & 2 deletions src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,9 @@ export default class Helpers {
return false
}

if (!fieldID) {
const field = fieldID && document.getElementById(fieldID)

if (!fieldID || !field) {
const availableIds = [].slice.call(fields).map(field => {
return field.id
})
Expand All @@ -886,7 +888,6 @@ export default class Helpers {
fieldID = form.lastChild.id
}

const field = document.getElementById(fieldID)
const $field = $(field)
if (!field) {
config.opts.notify.warning('Field not found')
Expand Down

0 comments on commit e0c0f2e

Please sign in to comment.