Conditional Show/Hide Child Terms on Edit Page I have a content type with a term reference. The terms have child terms. On the admin editing side, I want to show only top level terms until selected, then show only the child terms for that parent.
This to prevent having a ginormously long field.
Parent 1
  Child 1
  Child 2
Parent 2
  Child 3
  Child 4
Parent 3
...

When a user edits a piece of content, I want to only show the parent terms initially. Then show/hide the child terms when the parent is checked.
Parent 1
Parent 2 (checked)
  Child 3
  Child 4
Parent 3
Parent 4
...

I've used conditional fields, state API, and select (other) modules. But this is showing and hiding children on the same field. So it's a bit different.
Anyone have any advice for this scenario?
Off the top of my head, I would say that you can do this more cleanly with two '#type' =&gt; 'select' elements.
The first one would just contain the parent terms.
The second one would be set to
'#states' =&gt; [
  'disabled' =&gt; [
    ':input[name=&quot;parent_term&quot;]' =&gt; ['value' =&gt; ''],
  ],
],

Then you could use Drupal Form API #states to conditionally set the value of the second select element to the appropriate child terms, depending on which parent term is selected.
The most obvious alternative approach would be some hacky JavaScript.