Conditional Show/Hide Child Terms on Edit Page
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.