-
Notifications
You must be signed in to change notification settings - Fork 1.7k
added first solution #1824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
added first solution #1824
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,24 @@ | ||
| 'use strict'; | ||
|
|
||
| // write code here | ||
| function addingPlaceholderAndLabel(element, index, arr) { | ||
| const elementLabel = document.createElement('label'); | ||
|
|
||
| if (element.name) { | ||
| element.placeholder = | ||
| element.name.charAt(0).toUpperCase() + element.name.slice(1); | ||
| } | ||
|
|
||
| elementLabel.className = 'field-label'; | ||
|
|
||
| if (!element.id && element.name) { | ||
| elementLabel.htmlFor = element.name; | ||
| } | ||
|
Comment on lines
+13
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This conditional block is made ineffective by the unconditional assignment on line 17, which overwrites anything set here. The requirement is to set the |
||
|
|
||
| elementLabel.htmlFor = element.id; | ||
| elementLabel.textContent = element.name.toUpperCase(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the placeholder, this doesn't handle multi-word There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The text for the label should also have hyphens replaced with spaces. Additionally, based on the expected result image, it seems only the first letter should be capitalized, similar to the placeholder text (e.g., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the placeholder, this doesn't handle hyphens correctly. For |
||
| element.parentElement.prepend(elementLabel); | ||
| } | ||
|
|
||
| const allInputs = [...document.querySelectorAll('form input')]; | ||
|
|
||
| allInputs.forEach(addingPlaceholderAndLabel); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic does not correctly handle input names containing a hyphen, which was the main point of the previous review. For a name like
confirm-password, this producesConfirm-password. You need to first replace the hyphen with a space and then capitalize the string to get the requiredConfirm password.