0

I know there are several examples of this around, on a view with two exposed select list filters, I need to update the value of the second based on the value selected on the first. I can't even seem to get any debugging info on my callback, but the request is throwing a Drupal\Core\Form\Exception\BrokenPostRequestException. Here's the simple form alter I'm trying.

use Drupal\Core\Form\FormStateInterface;

function MODULENAME_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if($form_id == "views_exposed_form"){
    $form['field_article_value1_value']['#options']  = _MODULENAME_get_update_value1_values();
    $form['field_article_value2_value']['#options']  = _MODULENAME_get_value2_values();

    $form['field_article_value1_value']['#ajax'] = [
     'callback' => ['_MODULENAME_get_value2_values_ajax_callback'],
     'event' => 'change',
     'wrapper' => 'edit-field-article-value-wrapper',
     'progress' => [
     'type' => 'throbber',
     'message' => NULL,
     ],
  ];
}

function _MODULENAME_get_value2_values_ajax_callback(array &$form, FormStateInterface $form_state) : array {
  $markup = '<h1>Testing!</h1>';
  return ['#markup' => $markup];
}
0

This module might help: Views Dependent Filters

If you really want a custom solution take a peek at the code there and see if it helps, or help the D8 version get released :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.