drupal 8 refresh form / drupal 8 ajax form (and the better alternative)
I'll be honest. I spent most of today chasing my tail. The gist of the task today was that I wanted certain form elements to be exposed based upon a value chosen in a primary select box. I had a mental construct of how form element visibility should work, and in my head, it related to the ajax functionality and page rebuild in the forms API. I was way off.
Somehow, I've made it the better part of a decade in Drupal and worked extensively in the Form APi Validation module... and never heard of the #states attribute in the form API.
It works a little something like this...
$form['field_p_promotion_image']['#states'] = [ 'visible' => [ "select[name = 'field_p_promotion_type']" => array('value' => 'image'), ], ];
Man... that was so much simpler than anything I'd seen to date! I spent hours chasing this online, and I found lots of people just as far down the same wrong road as me, with no real working solution in sight. So there you have it... this is the actual direction you want to take to accomplish this task.
(Note to self: Get code rendering in a reasonable fashion in Drupal 8... when I'm not swamped doing other things!)