Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 54 additions & 7 deletions Form-Controls/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand All @@ -13,15 +13,62 @@ <h1>Product Pick</h1>
</header>
<main>
<form>
<!-- write your html here-->
<!--
try writing out the requirements first as comments
this will also help you fill in your PR message later-->
<div>
<label for="name">Name:</label>
<input
type="text"
id="name"
name="name"
required
minlength="2"
pattern="(\p{L}\p{M}*)+(['\- ](\p{L}\p{M}*)+)*"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good pattern. I tried Är, ää, O'Brien, Anne-Marie and 李明 and they all pass, while and A are rejected. One question: what does minlength="2" add that the pattern doesn't already do on its own?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The pattern accepts single characters and the requirement is at least 2 non space characters, which is why I used the min length

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good answer. The pattern controls which characters, minlength controls how many. Both are needed.

/>
<!--Regex. \p{L} Any unicode
character considered a letter. \p{M}* 0 or more unicode character that
could have accent. ()+ 1 or more of all of that.
['\- ] 1 space ' - character. (\p{L}\p{M}*)+)* then
0 or more of any letter again -->
</div>
<br />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These <br /> tags are only there to space the fields out. What would you reach for instead of line breaks to control spacing? (Not required for this task.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Using CSS with margins

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes. Margins in CSS, whenever you next style a form.

<div>
<label for="email">Email:</label>
<input
type="email"
id="email"
name="email"
required
placeholder="abc@example.com"
/>
</div>
<br />
<div>
<label for="colour">Colour</label>
<select name="colour" id="colour" required>
<option value="">Please select</option>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Starting the dropdown on an empty "Please select" option is the right way to make required work on a select. Well done.

<option value="white">White</option>
<option value="black">Black</option>
<option value="green">Green</option>
</select>
</div>
<br />
<div>
<label for="size">Size</label>
<select name="size" id="size" required>
<option value="">Please select</option>
<option value="xs">Extra Small</option>
<option value="s">Small</option>
<option value="m">Medium</option>
<option value="l">Large</option>
<option value="xl">Extra Large</option>
<option value="xxl">Extra Extra Large</option>
</select>
</div>
<br>
<button>Submit</button>
</form>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The form ends here without any button. Try filling it in on the deploy preview and submitting. What happens? Which element would let the user do that, and would the browser then run the validation you've written?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Nothing happens because I haven't added a button. Adding the button, then when clicking it the browser validates the inputs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's it. The button is what lets the browser run the checks you'd written.

</main>
<footer>
<!-- change to your name-->
<p>By HOMEWORK SOLUTION</p>
<p>By Mahir Shah</p>
</footer>
</body>
</html>
Loading