Dynamic form creation for custom action
Hello - is it possible to create a form with a dynamic number of fields if I am using a custom action on an edit page?
For example:
I've tried using a repeater but I don't want the user selecting the number of sections. I want to control the number sections and pre-populate them with information
27 Replies
You should be able to do something like this:
Then how would I generate a form using those fields?
Does the
form()
call have access to what the action()
returns?What do you mean? You return an array with your fields.
How can it? The actions runs after the form.
Do you want to set the form on the EditPage from within the Action? 🤔
Maybe not, but I can't think of a better way
I need something a little more complex than a relationship manager
Is there a way to use a custom footer on the bottom of an edit page?
Everything I'm trying to modify is related to the item, so I believe using the edit page makes sense
Or maybe a custom view for a relationship manager and then write my own logic?
Maybe explain what you are trying to achieve
Hey sorry I missed your reply. What I have is an app that has a menu of food items. Each item can have options added to it (i.e.: toppings on a sandwich). The manager needs to be able to select which options (and by extension, option categories) are available for the customer to see when they click on at item. I don't want all the options showing up. Only the ones the manager designates for that specific item
So what I need is a form that shows all the option categories (and options) to the manager
So they can select whether or not that category of options is visible to the customer
And then select which options within that category are visible
Meaning, maybe not all toppings are available for a specific type of sandwich
Can't that be solved with just a CheckboxList?
Yes it could! But how would I set up a dynamic number of lists?
There could be one category or 20
Those categories need to be stored somewhere right? Then just give them as an input to CheckboxList
Yes they are stored
I'm confused how to use the
form([])
call dynamically. Does it accept a callback?Yes. That's what I explained in my first answer.
Because then I could use a loop to generate the form that I need and then return that, right?
But what do you need the action for? I though this is just set on the EditPage
You don't even need a Loop with a Checkbox List
Oh I think I get it now. You want Categories and each have options underneath that.
yes
And I'm trying to use a modal on the page to achieve this
Can't you just work with dependant fields? Make a group for every categories options and toggle visibility if the category is checked
No need for a modal then
There are other fields that need to be editable as well. Two could be a toggle but another is a numeric value
which I don't think can be modified from a table like the toggle can do
can it?
Wait. What does a table have to do with this now?
And what's the issue with other fields? You can put as many as you want on an edit page?
Oh you're saying to just make it a part of the actual EditItem form
Yes
Ahhh
Group the category options and then do something like:
Oh thank you! Where can I find
Group
in the docs? I searched for it but all that comes up is Navigation and ActionsSorry, there is no Group. Use
Card
, Section
, Grid
Oh ok
And I would use this in
public static function form
? On the ItemResource?Yes
Got it
Thank you!
This has been so helpful
you’re welcome