Skip to content

Commit

Permalink
fix(frontend): remove any errors when cloning another item
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 30, 2024
1 parent 194c291 commit 0a38ff9
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions packages/frontend/components/add-another/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,26 @@ export const AddAnotherComponent = class extends HTMLElement {
const $item = $items[0].cloneNode(true);
const uid = Date.now().toString();

const $fields = $item.querySelectorAll("input, select, textarea");
const $fields = $item.querySelectorAll(".field--error");
for (const $field of $fields) {
$field.id = $field.id.replace("-0", `-${uid}`);
$field.name = $field.name.replace("[0]", `[${uid}]`);
$field.value = "";
$field.classList.remove("field--error");
}

const $errorMessages = $item.querySelectorAll(".error-message");
for (const $errorMessage of $errorMessages) {
$errorMessage.remove();
}

const $inputs = $item.querySelectorAll("input, select, textarea");
for (const $input of $inputs) {
$input.id = $input.id.replace("-0", `-${uid}`);
$input.name = $input.name.replace("[0]", `[${uid}]`);
$input.value = "";
$input.classList.remove(
"input--error",
"select--error",
"textarea--error",
);
}

const $labels = $item.querySelectorAll("label");
Expand Down

0 comments on commit 0a38ff9

Please sign in to comment.