Skip to content

Commit

Permalink
Update the form submit state
Browse files Browse the repository at this point in the history
  • Loading branch information
TomaszDziezykNetcentric committed Aug 20, 2024
1 parent 42f1633 commit cb50c31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions blocks/form/form-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const createSubmit = (fd) => {

const fieldWrapper = createFieldWrapper(fd);
fieldWrapper.append(button);
button.disabled = true;
return { field: button, fieldWrapper };
};

Expand Down
9 changes: 9 additions & 0 deletions blocks/form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,17 @@ export default async function decorate(block) {
if (!formLink) return;

const form = await createForm(formLink.href);
const submitButton = form.querySelector('button[type="submit"]');
block.replaceChildren(form);

/* enabling the submit button only when all of the checkboxes are checked */
const checkboxList = [...form.querySelectorAll('input[type="checkbox"]')];
checkboxList.forEach(checkbox => {

Check failure on line 107 in blocks/form/form.js

View workflow job for this annotation

GitHub Actions / build

Expected parentheses around arrow function argument
checkbox.addEventListener('input', () => {
submitButton.disabled = checkboxList.length !== checkboxList.filter(ch => ch.checked).length

Check failure on line 109 in blocks/form/form.js

View workflow job for this annotation

GitHub Actions / build

Expected parentheses around arrow function argument

Check failure on line 109 in blocks/form/form.js

View workflow job for this annotation

GitHub Actions / build

Missing semicolon
})

Check failure on line 110 in blocks/form/form.js

View workflow job for this annotation

GitHub Actions / build

Missing semicolon
});

form.addEventListener('submit', (e) => {
e.preventDefault();
const valid = form.checkValidity();
Expand Down
1 change: 1 addition & 0 deletions blocks/table/table.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.table {
overflow: auto;
width: 100%;
text-align: left;
}

.table .table-element {
Expand Down

0 comments on commit cb50c31

Please sign in to comment.