From f4dcb923a1de60a7bd56e39bc0249aecbc3b2f53 Mon Sep 17 00:00:00 2001 From: Tetiana Skuratovska Date: Mon, 30 Sep 2024 14:37:44 +0200 Subject: [PATCH] added new formatName for placeholder and textContent --- src/scripts/main.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index d1bc315d..aeb730f3 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -3,18 +3,20 @@ const allInput = document.querySelectorAll('form input'); allInput.forEach((input) => { - const formatPlaceholder = (inputName) => { + const formatName = (inputName) => { return inputName.replace(/([A-Z])/g, ' $1').trim(); }; - input.placeholder = formatPlaceholder( + const formattedName = formatName( input.name.charAt(0).toUpperCase() + input.name.slice(1), ); + input.placeholder = formattedName; + const newLabel = document.createElement('label'); newLabel.classList.add('field-label'); newLabel.setAttribute('for', input.id); - newLabel.textContent = input.name; + newLabel.textContent = formattedName; input.parentElement.insertBefore(newLabel, input); });