Skip to content

Commit

Permalink
fix: revert change made in e0c0f2e which declared field as a const pr…
Browse files Browse the repository at this point in the history
…ior to the fallback to selecting the last field in the form. This change also prevents incorrect removing of the last field in the case where a fieldID is provided but which was not found in the form

removeField will remove the field given in fieldID, or if no fieldID passed to the function then it will remove the last field in the form.
  • Loading branch information
lucasnetau committed Aug 23, 2023
1 parent 58baf4e commit 0b7e1bb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ export default class Helpers {
}

/**
* Remove a field from the stage
* Remove a given field from the stage or the last field if no fieldID is provided
* @param {String} fieldID ID of the field to be removed
* @param {Number} animationSpeed
* @return {Boolean} fieldRemoved returns true if field is removed
Expand All @@ -1018,9 +1018,7 @@ export default class Helpers {
return false
}

const field = fieldID && document.getElementById(fieldID)

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

const $field = $(field)
const fieldRowWrapper = $field.closest(this.formBuilder.rowWrapperClassSelector)
const field = document.getElementById(fieldID)
if (!field) {
config.opts.notify.warning('Field not found')
return false
}

const $field = $(field)
const fieldRowWrapper = $field.closest(this.formBuilder.rowWrapperClassSelector)

$field.slideUp(animationSpeed, function () {
$field.removeClass('deleting')
$field.remove()
Expand Down

0 comments on commit 0b7e1bb

Please sign in to comment.