How I can add a class on hook_form_views_exposed_form_alter on a filter particular radio button

53 Views Asked by At

I am using better expose filter with group filter and added two options All and upcoming radio button option Now I want to add a class to upcoming radio button and disable ajax call only on upcoming radio button because on upcoming click i want to hide some div so want custom jquery. FYI First radio button is -Any- that did not mentioned.

<div class="js-form-item form-item js-form-type-radio form-type-radio js-form-item-title form-item-title">
        <input data-drupal-selector="edit-title-2-sfsd" type="radio" id="edit-title-2--sfsdfdsf" name="title" value="2" class="form-radio">

        <label for="edit-title-2--sdfsdff" class="option">All </label>
      </div>

<div class="js-form-item form-item js-form-type-radio form-type-radio js-form-item-title form-item-title">
        <input data-drupal-selector="edit-title-2-sfsd" type="radio" id="edit-title-2--sfsdfdsf" name="title" value="2" class="form-radio">

        <label for="edit-title-2--sdfsdff" class="option">Upcoming </label>
      </div>

Below is my code:

function themename_form_views_exposed_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$view = $form_state->get('view');
if($view->id() == 'view_name') {
if($view->current_display == 'block_machinename') {      
  
   $form['title']['#options'][2]['#attributes']['class'][]= 'Test'; 
}

} }

0

There are 0 best solutions below