diff --git a/guides/release/tutorial/part-2/index.md b/guides/release/tutorial/part-2/index.md
index 36e556d77c..24f6f5bfd0 100644
--- a/guides/release/tutorial/part-2/index.md
+++ b/guides/release/tutorial/part-2/index.md
@@ -4,7 +4,7 @@ Hooray, you've made it to the second part of the tutorial! In the following sect
Along the way, we'll also add some new features to our Super Rentals app. By the end of this section, we'll have implemented some search functionality and refactored a good bit of our code to use some new Ember concepts
-
+
In part two, we'll cover the following concepts:
diff --git a/guides/release/tutorial/part-2/provider-components.md b/guides/release/tutorial/part-2/provider-components.md
index a7fcc207da..f955ffc625 100644
--- a/guides/release/tutorial/part-2/provider-components.md
+++ b/guides/release/tutorial/part-2/provider-components.md
@@ -4,11 +4,11 @@ In this chapter, we'll work on adding a new search feature, and refactor our `in
-
+
During this refactor, you will learn about:
-- Using Ember's built-in `` component
+- Using forms
- The provider component pattern
- Using block parameters when invoking components
- Yielding data to caller components
@@ -17,9 +17,9 @@ During this refactor, you will learn about:
As our app grows and as we add more features to it, one thing that would be really nice to have is some search functionality. It would be great if our users could just type a word into a search box and our app could just respond with matching and relevant rentals. So how could we go about implementing this feature?
-Well, we can start simple. Before we worry about implementing the "search" part of this feature, let's just get something on the page. The first step is to add an `` tag to our `index` page, and make it look pretty with a class.
+Well, we can start simple. Before we worry about implementing the "search" part of this feature, let's just get something on the page. The first step is to add a form with an `` tag to our `index` page, and make it look pretty with a class.
-```handlebars { data-filename="app/templates/index.hbs" data-diff="+8,+9,+10,+11,+12" }
+```handlebars { data-filename="app/templates/index.hbs" data-diff="+8,+9,+10,+11,+12,+13,+14" }
Welcome to Super Rentals!
We hope you find exactly what you're looking for in a place to stay.
@@ -27,10 +27,12 @@ Well, we can start simple. Before we worry about implementing the "search" part
-
+
{{#each @model as |rental|}}
@@ -58,10 +60,12 @@ Let's start simple again and begin our refactor by creating a new template for o
```handlebars { data-filename="app/components/rentals.hbs" }
-
+
{{#each @rentals as |rental|}}
@@ -73,7 +77,7 @@ Let's start simple again and begin our refactor by creating a new template for o
There is one minor change to note here: while extracting our markup into a component, we also renamed the `@model` argument to be `@rentals` instead, just in order to be a little more specific about what we're iterating over in our `{{#each}}` loop. Otherwise, all we're doing here is copy-pasting what was on our `index.hbs` page into our new component template. Now we just need to actually use our new component in the index template where we started this whole refactor! Let's render our `` component in our `index.hbs` template.
-```handlebars { data-filename="app/templates/index.hbs" data-diff="-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,+19" }
+```handlebars { data-filename="app/templates/index.hbs" data-diff="-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-20,+21" }
Welcome to Super Rentals!
We hope you find exactly what you're looking for in a place to stay.
@@ -81,10 +85,12 @@ There is one minor change to note here: while extracting our markup into a compo
-
+
{{#each @model as |rental|}}
@@ -198,28 +204,45 @@ Now, if we try running our tests, they should all pass after making this change.
-## Using Ember's ``
+## Using a `form`
-Now that we have our component all set up, we can finally wire up our search box and store our search query! First things first: let's create a component class to store our query state.
+Now that we have our component all set up, we can finally wire up our search box and store our search query! First things first: let's create a component class to store our query state and handle events from the `form` element:
```js { data-filename="app/components/rentals.js" }
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
+import { action } from '@ember/object';
export default class Rentals extends Component {
@tracked query = '';
+
+ @action
+ updateQuery(event) {
+ let formData = new FormData(event.currentTarget);
+ this.query = formData.get('rental-search-term');
+ }
+
+ @action
+ handleSubmit(event) {
+ event.preventDefault();
+ this.updateQuery(event);
+ }
}
```
Next, we'll wire up our query state in the component template.
-```handlebars { data-filename="app/components/rentals.hbs" data-diff="-4,+5" }
+```handlebars { data-filename="app/components/rentals.hbs" data-diff="-2,+3,-6,+7,+9" }
-
+
{{#each @rentals as |rental|}}
@@ -229,9 +252,7 @@ Next, we'll wire up our query state in the component template.
```
-Interesting! There are a few things happening in this one-line template change. First, we're moving from using a plain HTML `` tag to using an `` tag instead! As it turns out, Ember provides us with a helpful little _[`` component](../../../components/built-in-components/#toc_input)_ for this exact use case. The `` component is actually just a wrapper around the `` element.
-
-Ember's `` component is pretty neat; it will wire up things behind the scenes such that, whenever the user types something into the input box, `this.query` changes accordingly. In other words, `this.query` is kept in sync with the value of what is being searched; we finally have the perfect way of storing the state of our search query!
+[`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) is a built-in JavaScript object for handling forms. It requires the `name` attribute on the `input`. We handle both `submit` and `input` events for the form so that the query updates both when the user types into the input and when they submit the form.
@@ -275,12 +296,15 @@ In our component template, we are not actually _rendering_ anything. Instead, we
Well, in order to answer this question, let's look at how the data that we're yielding is being used in the `` component.
-```handlebars { data-filename="app/components/rentals.hbs" data-diff="-8,-9,-10,+11,+12,+13,+14,+15" }
+```handlebars { data-filename="app/components/rentals.hbs" data-diff="-11,-12,-13,+14,+15,+16,+17,+18" }
-
+
{{#each @rentals as |rental|}}
@@ -330,7 +354,7 @@ This is called the _provider component pattern_, which we see in action with one
Okay, now that we have a better sense of which component is rendering what and the theory behind why all of this is happening, let's answer the big unanswered question: does this even work? If we try out our search box in the UI, what happens?
-
+
Hooray, it works! Awesome. Now that we've tried this out manually in the UI, let's write a test for this new behavior as well.
diff --git a/public/downloads/style.css b/public/downloads/style.css
index 04943f2349..9d4dc80e14 100644
--- a/public/downloads/style.css
+++ b/public/downloads/style.css
@@ -129,6 +129,12 @@ p {
font-style: italic;
}
+.rentals form p {
+ font-size: 80%;
+ display: block;
+ text-align: center;
+}
+
.rentals input {
padding: 11px;
font-size: 18px;
diff --git a/public/images/tutorial/part-2/ember-data/detailed@2x.png b/public/images/tutorial/part-2/ember-data/detailed@2x.png
index 538dc91c20..677ae1b10e 100644
Binary files a/public/images/tutorial/part-2/ember-data/detailed@2x.png and b/public/images/tutorial/part-2/ember-data/detailed@2x.png differ
diff --git a/public/images/tutorial/part-2/provider-components/filtered-results@2x.png b/public/images/tutorial/part-2/provider-components/filtered-results@2x.png
index 64165b01cb..0315862221 100644
Binary files a/public/images/tutorial/part-2/provider-components/filtered-results@2x.png and b/public/images/tutorial/part-2/provider-components/filtered-results@2x.png differ
diff --git a/public/images/tutorial/part-2/route-params/grand-old-mansion@2x.png b/public/images/tutorial/part-2/route-params/grand-old-mansion@2x.png
index 538dc91c20..677ae1b10e 100644
Binary files a/public/images/tutorial/part-2/route-params/grand-old-mansion@2x.png and b/public/images/tutorial/part-2/route-params/grand-old-mansion@2x.png differ
diff --git a/public/images/tutorial/part-2/service-injection/share-button@2x.png b/public/images/tutorial/part-2/service-injection/share-button@2x.png
index 538dc91c20..b5cc6bd4c9 100644
Binary files a/public/images/tutorial/part-2/service-injection/share-button@2x.png and b/public/images/tutorial/part-2/service-injection/share-button@2x.png differ