Table of Contents

Create an Add To Favorites Feature

Lesley Updated by Lesley

This article uses Connections and Record Rules to create a workflow where users can view a record and save it for later viewing.

Scenario

DataBrew has a "Recipes" page where you can share your own crazy coffee brew ideas. Users would like a way to be able to save these recipes so they can try them out at a later time by simply clicking a link.

In this example, we will be building a Favorites feature to allow Users to add Recipe records to their own list of Favorites.

How it looks / See it in action

Users will see a list of records along with a link to Add to Favorites. Once added, users can access their Favorites at any time from a separate page

Steps

Create a Favorites Table

In the Data section of the Knack Builder, create a new table called "Favorites" using the green "+" button:

Add a Connection Pointing to the Original Table

In your newly created Favorites table, add a Connection Field that points to the original table. This original table is the table containing records your Users will favorite. Here we point the connection to the Recipes table:

Add a Connection to the User Role

Add another Connection field to the Favorites table pointing to the User. If you want ALL user roles to have access to the Favorites feature, connect to the User. In this app, only Members have access to the feature:

Here you can find more information to working with connections.
Notice how there’s no other recipe-related fields? With the single connection, we can display any Recipe field directly from the Favorite record

We can delete the Favorites Name field since it won’t store any information. In the end, our Favorites table consists of only 2 fields:

Now that your tables are setup, it’s time to create a Page that allows the user to favorite specific records.

In this example, we will add a List View to display recipes. The View will contain a link to view more details, where we can use an ‘Edit Recipe’ Form as a trigger to create the Favorite record automatically.

Add a Records View

Using the Add Page Wizard, add a new page that displays the records that users can favorite (Recipes):

You can select any view type you’d like for the records. We’re using a grid view for this example:

In order for the user to be able to add a new Favorite record, make sure you include the Form to add a connected Favorite:

Remove the Form Inputs

If you open the Add Favorites Form we just created, you’ll notice that the User connection field is available. This is not ideal for the user who will be submitting the form. We can populate the User field with a Record Rule, therefore let’s remove the User input from the Form.

From the Inputs tab, remove the form input field by hovering over the fields and selecting the trashcan icon.

Connect the logged-in User with Record Rules

Next From the Form Rules tab, select Record Rules, select Add Rule to add a new record rule to your form.

For this new rule add the following settings:

  • Action: Select "Update this record"
  • When: Leave as "Every form submission".
  • Value: Set your User Role connected to the Favorites table to "the logged-in User Role"
Change Submit Button Text

We can make this more user-friendly by changing the text from the Form’s Submit button.

From the Settings section of the Form editor, change the Submit Button Text to "Add to Favorites."

Here you can find more information on Form and Detail views.

Create a View of User's Favorites

Now that users can favorite records, they will want to see which records are on their list of favorites.

Using the Add Page wizard again, add a new Page restricted to the specific User Role. You can use any view-type for this, this example uses a grid view with a link to view more details:

Control which fields the User sees for thier Favorites

By default, the view is only going to display the two connection fields present in the Favorites table. To allow you users to see other fields from the original records, add fields from the connected table to the list.

From the Columns section of the grid view editor, select the "Connections" tab to view a list of all fields from connected tables:

Optional Features

Adding Notes

What if users to add notes to each record they favorite? This can be done by adding a Paragraph Field to the Favorites table.

Then include this field in the "Add to Favorites" form view, so your form will no longer be blank. Your users will now be able to add notes when they Favorite a record.

Enable the Modal Popup

With this current setup, the user would be taken to a separate page in order to access the Add to Favorites button. It would be a much smoother process if they could do it directly from the grid without having to leave the list.

From the Settings tab of your Details page, enable the option titled "Display page in a modal popup":

How did we do?

How To Create Discount Codes

How to Access Private Records Without a Login

Contact