From e5b8094d053e872ce6c9f4c270188edfd1a33498 Mon Sep 17 00:00:00 2001 From: Sergey Ivanov Date: Mon, 20 Apr 2026 09:25:19 +0300 Subject: [PATCH 1/3] add task solution --- src/scripts/main.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..b82895330 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,21 @@ 'use strict'; +'use strict'; + +const inputs = document.querySelectorAll('input'); + +inputs.forEach((input) => { + const label = document.createElement('label'); + + label.classList.add('field-label'); + + // 2. Прив’язуємо label до input через id + label.setAttribute('for', input.id); + + const text = input.name.charAt(0).toUpperCase() + input.name.slice(1); + + label.textContent = text; + + input.placeholder = text; -// write code here + input.parentElement.prepend(label); +}); From a2d8ecead3c41353ed384116c6cf25531100d808 Mon Sep 17 00:00:00 2001 From: Sergey Ivanov Date: Tue, 21 Apr 2026 15:41:50 +0300 Subject: [PATCH 2/3] add task solution --- src/scripts/main.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index b82895330..c26d2ab5d 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,21 +1,30 @@ 'use strict'; -'use strict'; -const inputs = document.querySelectorAll('input'); +// беремо ВСІ форми на сторінці +const forms = document.querySelectorAll('form'); + +forms.forEach((form) => { + // беремо input ТІЛЬКИ всередині конкретної форми + const inputs = form.querySelectorAll('input'); -inputs.forEach((input) => { - const label = document.createElement('label'); + inputs.forEach((input) => { + // створюємо label + const label = document.createElement('label'); - label.classList.add('field-label'); + label.classList.add('field-label'); - // 2. Прив’язуємо label до input через id - label.setAttribute('for', input.id); + // прив’язка через id + label.setAttribute('for', input.id); - const text = input.name.charAt(0).toUpperCase() + input.name.slice(1); + // текст із name (з великої літери) + const text = input.name.charAt(0).toUpperCase() + input.name.slice(1); - label.textContent = text; + label.textContent = text; - input.placeholder = text; + // placeholder + input.placeholder = text; - input.parentElement.prepend(label); + // вставляємо label перед input + input.parentElement.prepend(label); + }); }); From b053762685b13e151f653698939ddef126ce7af0 Mon Sep 17 00:00:00 2001 From: Sergey Ivanov Date: Tue, 21 Apr 2026 15:48:08 +0300 Subject: [PATCH 3/3] fix: update demo link in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d24722b51..3cce7e2c5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ 1. Replace `` with your Github username in the link - - [DEMO LINK](https://.github.io/js_task_fix_form_DOM/) + - [DEMO LINK](https://ivanov-serg.github.io/js_task_fix_form_DOM/) 2. Follow [this instructions](https://mate-academy.github.io/layout_task-guideline/) - Run `npm run test` command to test your code; - Run `npm run test:only -- -n` to run fast test ignoring linter;