Fix bug with duplication of fields when re-registering existing fields

This commit is contained in:
Andrew Kingston 2021-11-18 14:43:02 +00:00
parent 9f30599ec1
commit 8e58cde6ec
1 changed files with 8 additions and 1 deletions

View File

@ -83,6 +83,8 @@
return fields.find(field => get(field).name === name)
}
$: console.log(fields)
const formApi = {
registerField: (
field,
@ -136,7 +138,12 @@
})
// Add this field
fields = [...fields, fieldInfo]
if (existingField) {
const otherFields = fields.filter(info => get(info).name !== field)
fields = [...otherFields, fieldInfo]
} else {
fields = [...fields, fieldInfo]
}
return fieldInfo
},