Skip to content

Commit

Permalink
pkp/pkp-lib#10918 Bug fix, to correctly handle removing value from fi…
Browse files Browse the repository at this point in the history
…eld with 'selected' array.
  • Loading branch information
jardakotesovec committed Feb 11, 2025
1 parent 4294a72 commit 1a12104
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/composables/useForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function mapFromSelectedToValue(selected) {
return selected.map((iv) => iv.value);
}

export function isFieldValueArray(field) {
return Array.isArray(field.value) || field.selected ? true : false;
}

export function useForm(_form, {customSubmit} = {}) {
const form = ref(_form);

Expand Down Expand Up @@ -131,8 +135,15 @@ export function useForm(_form, {customSubmit} = {}) {

function removeFieldValue(fieldName, fieldValue) {
const value = getValue(fieldName);
const field = getField(form.value, fieldName);
if (Array.isArray(value)) {
const newValue = value.filter((v) => v !== fieldValue);
let newValue = null;
if (field.selected) {
newValue = field.selected.filter((v) => v.value !== fieldValue);
} else {
newValue = value.filter((v) => v !== fieldValue);
}

setValue(fieldName, newValue);
} else {
clearFormField(fieldName);
Expand Down Expand Up @@ -191,6 +202,7 @@ export function useForm(_form, {customSubmit} = {}) {
setValues,
getValue,
removeFieldValue,
isFieldValueArray,
clearForm,
form,
connectWithPayload,
Expand Down

0 comments on commit 1a12104

Please sign in to comment.