A pixel for Quora tracking

Getting started with Smart Action Forms and Dynamic Fields in Forest Admin

In this article, we'll take a look at what Smart Action Forms are, and how you can make them even more interactive than before using Dynamic Fields.

Getting started with Smart Action Forms and Dynamic Fields in Forest Admin

Smart Actions are one of the most powerful features Forest Admin has. With their help, you can implement your own business logic to be executed at any time at the push of a button, whether it’s something like issuing refunds, or changing order statuses. However, if you want to take your Smart Actions to the next level and implement some more complex functions, sooner or later, you’ll have to set up some Smart Action Forms to go with them. Let’s take a look at what they are, and how you can make them as dynamic as possible.

What are Smart Action Forms?

Smart Action Forms let your users provide more information when they’re using your Smart Actions, or even interact with them in different ways. What’s the point, you might ask? Well, you might have specific business logics that require you to have some sort of user input before triggering a Smart Action, for example, specifying a reason for blocking a user’s account, or uploading necessary documents, when needed. This is when Smart Action Forms come into the picture, allowing you to expand what you can do and make your functions more interactive.

Tip: check out our documentation for a list of all input values usable with Smart Action Forms.

Making your Smart Action Forms dynamic

While oftentimes, static forms and fields are enough to make your business logic work, sooner or later, you might come across a situation where you want to go even further, and make your form adapt to its context. In Forest, you can extend your Smart Action Form’s logic through a handy feature called hooks — these allow you to run specified actions upon a specific event happening, for example, a form being filled out. There are two types of hooks:

The load hook is called when the form loads, allowing you to change its properties upon loading.

The change hook is called whenever you interact with the fields of the Smart Action Form, allowing you to change a field property — or the field itself — based on previous fields values.

Tip: you can even pre-fill your forms with data coming from your records themselves to make things even smoother for your users.

The first thing you can make dynamic is your form’s data. This way, you’re not actually changing the form and field you have on the screen — you only change the value of it. A few typical examples of this could include fields where you first select a country, then a city, or if you need to specify something such as a dispute type for a customer complaint. If you’re curious , check out our example code and the documentation about how such a dynamic form value is made.  

But there’s one more step you can take to make your Smart Action Form as dynamic as possible: make the actual fields change upon input. What this means is that upon user interaction, the actual field structure will change according to your pre-programmed logic — we’re talking about the fields themselves rather than the values they hold, in this case.

For example, once you select your choice within the first field, another could pop up right below it depending on what you selected. If we take the previous examples, you could want to add a field dynamically to specify a district only when a major city is selected, or have different types of fields pop up depending on the price range of a dispute. To see how you can get started with Dynamic Fields, check out our documentation.

Here’s a video of what fully implemented Dynamic Fields in a Smart Action Form look like:

Of course, there are many other advanced features in Forest Admin that let you expand on what you can do with your internal tool, and make your business even more effective — if you’ve enjoyed this article, don’t forget to check out our piece on Moderation Views, or take a look at how you can create your own Smart Charts. You can also follow us on Twitter, Facebook, and LinkedIn to get constant updates about our new features. See you again soon!