Dynamic admin fields in V5

Wondering if there’s anything new around dynamic fields in the SS admin .

I know about and have used display-logic many times. It’s not very dynamic as the values to check against are hard coded.
I have seen dependant-dropdown. Not used but looks unlikely or at least cumbersome to define the data sources.

Nothing else?

What I’m trying to achieve is:

  1. User makes a selection from select/dropdown field
  2. A checkboxlist is displayed with options related to/based on the id of the above selection (this is a $has_many)
  3. Checking options in the above checkboxlist shows related checkboxlists and their values ($many_many) for the selections in step 2 above

You’re basically selecting branches of a tree to limit the related applicable options in step 3.

Any ajax type fields or ways to implement such a thing?

From what you’ve described it sounds like you essentially want the functionality provided by dependant-dropdown - perhaps combined with display-logic to handle whether the dependent field is displayed or not - but in a CheckBoxSetField instead.

You mentioned that the dependent dropdown module seems “cumbersome to define the data sources” - but it really is quite simple - the example in the README shows how it works. Is there something specific about it which makes you say it seems cumbersome?

The only alternative that I’m aware of at the moment would be to implement your own custom form field, javascript-and-all.

Thanks for replying.

I say cumbersome because it looks like I’ll need to pre-define all the branches/relations/possible choices and their outcomes at once. That is likely to be many hundreds.

Also, the docs show hard coded values not orm one-many and many-many type relations. I discounted it as an option so haven’t looked into the feasibility of that being dynamic.

From your answer there isn’t other fields for this so I’ll see how far I get with what’s available.

Edit:
Okay, too hasty on DependantDropdownField. This works fine:

$dataSource = function($val) {
   return ListingSubClassification::get()->filter(['ClassificationID' => $val])->map();
};

So far I created a DependantCheckboxsetField based on DependentDropdown works onload not on change due to the JS needing to be rewritten for checkboxes instead of another select.

1 Like

Sweet, sounds like you have a way forward