Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Forms and Controls for Everyone (Summary)

Sam’s recipe box is ready.

What You Can Do Now

You can now take structured input through a validated form, and build controls that work with a keyboard alone and tell screen-reader users what changed.

The Recipe Box, No Mouse

Each piece began on Sam’s shopping list. Now, with no mouse, add Pea soup and press Enter. In a form with a submit button, Enter sends it, and event.preventDefault() in your submit listener keeps the page in place.

FormData collects the named fields as strings, such as "4" for servings and "on" for a ticked checkbox, and your code builds the record from them with Number() and has().

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Sam’s recipe box is ready. You can now take structured input through a validated form, and build controls that work with a keyboard alone and tell screen-reader users what changed.

00:14 Each piece began on the shopping list. Now, with no mouse, add Pea soup and press Enter. In a form with a submit button, Enter sends it, and preventDefault keeps the page in place.

00:27 FormData collects the named fields as strings, and your code builds the record. Try Banana bread, and your setCustomValidity rule refuses it: it’s already in the box.

00:41 Tab past the boxes, since the slash shortcut skips them. Slash jumps to Filter, and soup leaves two recipes.

00:50 Tab reaches a real button but skips clickable divs. The focus ring shows where you are, and labels name boxes for screen readers. Delete the lentil soup, and a showModal dialog asks first.

01:03 Confirm. The status line announces it, and the focus moves to the next button.

01:10 Listen for submit on the form, and cancel its default. An unchecked checkbox isn’t false in FormData: it’s missing. Let the browser check the basic rules, and add your own for the rest.

01:24 Test with the keyboard alone. Move the focus to the next step, and announce results in a status region that exists at load. Clear the filter and reload, and the box forgets every change.

01:38 The lentil soup is back, and Pea soup is gone. Saving comes later in the recipe box’s story. For any term, try the JavaScript Glossary. Enjoy cooking with Sam, and thanks for watching.

Become a Member to join the conversation.