Skip to content

Develop#1821

Open
Humenyuk1991 wants to merge 3 commits intomate-academy:masterfrom
Humenyuk1991:develop
Open

Develop#1821
Humenyuk1991 wants to merge 3 commits intomate-academy:masterfrom
Humenyuk1991:develop

Conversation

@Humenyuk1991
Copy link

[ ПОСИЛАННЯ НА ДЕМОНСТРАЦІЮ ] ( https://Humenyuk1991.github.io/js_task_fix_form_DOM/ )

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

I am requesting changes because there are a couple of issues that can break correctness and HTML validity, even though the core behavior is well implemented. You currently set input.id = input.name in src/scripts/main.js, which will create duplicate id values when multiple inputs share the same name (for example, radio groups), and that means labels’ for attributes may not reliably point to a unique input [CHECKLIST ITEM #8]. Please generate unique IDs instead (e.g., include a counter or form/index suffix) so each input has a distinct id while still being derived from name.

Additionally, the script processes all inputs without filtering by type, so controls like type="submit", type="button", type="reset", and type="hidden" can receive labels and placeholders, which is incorrect for those non-data controls and conflicts with the intent of adding labels only to actual form fields [CHECKLIST ITEMS #1, #2]. Add a guard early in the loop to skip these types before creating labels/placeholders. Once you fix the unique-id issue and skip non-field input types, your solution will fully meet the task requirements; the rest of the implementation (using name, capitalizing label/placeholder, inserting labels as siblings, etc.) looks solid and on the right track.


✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +13 to +15
if (!input.name) {
return;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning early for inputs without a name (if (!input.name) return;) aligns with the requirement to rely on input name (checklist item #3), but double-check test expectations — if tests expect every input to be handled regardless of name, this will fail. If the intent is to only handle named fields, this is fine.

Comment on lines 17 to 19
if (!input.id) {
input.id = input.name;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting input.id = input.name will create duplicate IDs when multiple inputs share the same name (for example, radio groups). Duplicate id values break validity and make label.for ambiguous. Consider generating unique ids (e.g. ${input.name}-${counter}) instead of reusing name. This relates to checklist item #8 (label for must point to the input id).

Comment on lines 12 to 23
inputs.forEach((input) => {
if (!input.name) {
return;
}

if (!input.id) {
input.id = input.name;
}

const wrapper = input.parentElement;

if (!wrapper || !input.id) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script does not filter by input.type. Controls like type="submit", type="button", type="reset" or type="hidden" usually should not receive labels/placeholders. Add a check to skip these types before creating labels/placeholders so only actual form fields are processed.

Comment on lines 32 to 33
const text = input.name.charAt(0).toUpperCase() + input.name.slice(1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalizing the placeholder/label text with input.name.charAt(0).toUpperCase() + input.name.slice(1) satisfies the 'capitalize' requirement, but note that name values with dashes/underscores won't be prettified further. If prettier labels are required, transform name (replace -/_ with space and capitalize each word).

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

I am approving your solution! You've made excellent progress, successfully addressing all critical issues from the previous review. Your implementation correctly generates unique IDs for inputs, effectively filters non-field input types like submit and hidden, and ensures proper label association. All core requirements, including adding labels, setting capitalized placeholders, and correct DOM manipulation, are well met. While the task specified changing only main.js, the modifications to README.md, package-lock.json, and package.json are minor deviations and do not impact the core functionality or completion of the task's primary objectives within main.js. Great work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants