Skip to content

Commit

Permalink
added new formatName for placeholder and textContent
Browse files Browse the repository at this point in the history
  • Loading branch information
TSkuratovska committed Sep 30, 2024
1 parent 2f55c2f commit f4dcb92
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit f4dcb92

Please sign in to comment.