fix condition remove

This commit is contained in:
Pete Matsyburka
2025-08-28 10:31:19 +03:00
parent 6542804f44
commit 36bee92e8e
2 changed files with 26 additions and 12 deletions
+25 -11
View File
@@ -1265,24 +1265,31 @@ export default {
if (!field.areas.length) { if (!field.areas.length) {
this.template.fields.splice(this.template.fields.indexOf(field), 1) this.template.fields.splice(this.template.fields.indexOf(field), 1)
this.template.fields.forEach((f) => { this.removeFieldConditions(field)
(f.conditions || []).forEach((c) => { }
this.save()
},
removeFieldConditions (field) {
this.template.fields.forEach((f) => {
if (f.conditions) {
f.conditions.forEach((c) => {
if (c.field_uuid === field.uuid) { if (c.field_uuid === field.uuid) {
f.conditions.splice(f.conditions.indexOf(c), 1) f.conditions.splice(f.conditions.indexOf(c), 1)
} }
}) })
}) }
})
this.template.schema.forEach((item) => { this.template.schema.forEach((item) => {
(item.conditions || []).forEach((c) => { if (item.conditions) {
item.conditions.forEach((c) => {
if (c.field_uuid === field.uuid) { if (c.field_uuid === field.uuid) {
item.conditions.splice(item.conditions.indexOf(c), 1) item.conditions.splice(item.conditions.indexOf(c), 1)
} }
}) })
}) }
} })
this.save()
}, },
pasteField () { pasteField () {
const field = this.template.fields.find((f) => f.areas?.includes(this.copiedArea)) const field = this.template.fields.find((f) => f.areas?.includes(this.copiedArea))
@@ -1715,8 +1722,15 @@ export default {
}) })
}) })
this.template.fields = this.template.fields = this.template.fields.reduce((acc, f) => {
this.template.fields.filter((f) => !removedFieldUuids.includes(f.uuid) || f.areas?.length) if (removedFieldUuids.includes(f.uuid) && !f.areas?.length) {
this.removeFieldConditions(f)
} else {
acc.push(f)
}
return acc
}, [])
this.save() this.save()
} }
+1 -1
View File
@@ -239,7 +239,7 @@ module Submissions
item['conditions'].each_with_object([]) do |condition, acc| item['conditions'].each_with_object([]) do |condition, acc|
result = result =
if fields_index[condition['field_uuid']]['submitter_uuid'] == include_submitter_uuid if fields_index.dig(condition['field_uuid'], 'submitter_uuid') == include_submitter_uuid
submitter_conditions_acc << condition if submitter_conditions_acc submitter_conditions_acc << condition if submitter_conditions_acc
true true