Scenario
You would like to have a single button that updates a field to a custom value when clicked. This creates a one-click process that allows users to make quick updates and prevents them from inputting the wrong information.
Some example use cases of this would be:
- A button that approves a project or event
- A button that updates the status of a contact in a sales pipeline
- A button that marks an invoice as paid
To do this, you'll use a form with a record rule to set the value but remove all fields.
Here's a button for approving projects in action:
Requirements
If this is your first time creating an app, you'll need to know some basics about adding objects, fields, pages, and views. You can start by watching our "Introducing Knack" video tour and then working through the articles in our Get Started section.
Steps
In this example, you will create a button that approves a project.
Create a Project Object
In the Data section of the builder, create an object to store your projects.
For this example, you'll need at least one field for the project's name, but you can feel free to include any other fields you'd like:
Add a Status Field
In the Projects object, add a multiple choice field and call it "Status." This field will track whether a project has been approved or not.
Include the following options:
- Pending Approval
- Approved
- Rejected
Set the Default Option to "Pending Approval" so all new projects created are automatically set to that status:
Create a Projects Page & Table
In the Pages section of the Builder, create a page with the following settings:
1. Using the Projects object.
2. A table and links to view more details for each project.
3. Call the page "Projects":
Create and Prepare the Edit Project Form
1. Go to the Project Details page you created.
2. Add a new form for editing that page's project.
3. Click on the new form to edit it:
4. Click on the edit pencil icon next to the form title to rename it to "Approve Project."
5. Remove all fields from the form by clicking on the trash can icon for the group:
Add a Record Rule
1. Go to the Form Rules section.
2. Click on the Record Rules tab.
3. Click the Add Rule button:
4. Set up the record rule as follows:
- Action: Update this record (the default option)
- When: Every form submission (the default option)
- Values: Set "Status" to a custom value "Approved"
Optional Features
Display Button in a Modal Popup
Instead of navigating to a details or edit page, you can display your form button in a pop up so users aren't redirected to a new page.
Here's this option in action:
To set up this option so your button is displayed in a modal pop up:
1. Add a link column to the Projects table that edits the project. This will create a new page with a form on it.
2. Edit the link column you just created with the following settings:
- Column Header to "Approve Project"
- Link Text to "approve"
3. Go to the Edit Project page you created when you added the link column to the table and click on the form on that page to edit it:
4. Follow the same steps for editing your form from step 3.4. in this article.
5. Follow the same steps for adding a record rule from step 3.5 in this article.
6. Go to the page Settings tab and check the box next to "Display page in a modal popup." This is what will make your button show up in a popup.