Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
This requires a few changes before it can be approved. You've correctly identified the necessary elements and written the logic to create labels and placeholders. However, this logic is currently placed inside an 'input' event listener, which causes it to run every time a user types into a field. This results in multiple labels being created, instead of just one when the page loads.
To fix this, please move the code that creates and appends the <label> element and sets the placeholder out of the addEventListener callback. This logic should be placed directly inside your forEach loop so that it executes only once for each input as soon as the script runs.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
src/scripts/main.js
Outdated
| input.addEventListener('input', () => { | ||
| if (input.value.trim() === '') { | ||
| input.classList.add('error'); | ||
| } else { | ||
| input.classList.remove('error'); | ||
| } | ||
|
|
||
| const label = document.createElement('label'); | ||
|
|
||
| label.classList.add('field-label'); | ||
| label.setAttribute('for', input.id); | ||
| label.textContent = input.name; | ||
|
|
||
| const placeholderText = | ||
| input.name.charAt(0).toUpperCase() + input.name.slice(1); | ||
|
|
||
| input.setAttribute('placeholder', placeholderText); | ||
| input.parentElement.insertBefore(label, input); | ||
| }); |
There was a problem hiding this comment.
The logic to create and add labels and placeholders should run once when the script loads, not every time the user interacts with an input field. By placing this logic inside an 'input' event listener, a new label is created on every keystroke, which doesn't meet the requirements. The DOM manipulation should happen directly inside the forEach loop.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job addressing the previous feedback on the event listener! The logic is now correctly set up to run once on page load. However, there is one critical issue that needs to be fixed. In src/scripts/main.js, you are inserting each <label> element into the DOM twice because the input.parentElement.insertBefore(label, input) call is duplicated within your forEach loop. This creates incorrect output with duplicate labels. Please remove the second, redundant insertBefore call to resolve the issue. Once that's done, this will be ready for approval!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
src/scripts/main.js
Outdated
| input.name.charAt(0).toUpperCase() + input.name.slice(1); | ||
|
|
||
| input.setAttribute('placeholder', placeholderText); | ||
| input.parentElement.insertBefore(label, input); |
There was a problem hiding this comment.
This line inserts the label element into the DOM a second time. Since the exact same operation was already performed on line 10, this line is redundant and should be removed.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on this revision! I am approving your solution. You've successfully addressed the feedback from the previous review by removing the duplicate code, and the script now functions exactly as required. All requirements for adding labels and capitalized placeholders have been met. Don't worry about the failed check; it's due to an environment issue and is not related to your code changes. Great job!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.