I have a block that i render it this way:
public function build() { $ filterForm = \Drupal::formBuilder()->getForm('Drupal\smeno\Form\FilterForm'); $ renderArray['filterform'] = $ filterForm; $ renderArray['McRefund_data'] = $ this->getMcRefund(); return [ '#theme' => 'Remboursement-sur-compte', '#McRefund_build_data' => $ renderArray, ]; }
So as you can see within this block i render a form and data(McRefund_build_data) which i put in a table. the purpose of the form is to filter the data and put the response back in the block so that the block get rendered with the new filtered data. for this process i want to use ajax as i don’t want the page to reload.
So i tried to add this on the BuilForm:
$ form['actions']['#type'] = 'actions'; $ form['actions']['submit'] = array( '#type' => 'submit', '#value' => $ this->t('OK'), '#button_type' => 'primary', '#prefix' => '<div class="tc btn_pay relative">', '#suffix' => '</div> </div>', '#attributes' => array( 'class' => array('proximabold', 'tc', 'transition', 'no-underline', 'ph3', 'pv2', 'mb2', 'dib', 'white'), ), '#ajax' => [ //'callback' => 'Drupal\smeno\Controller\RemboursementsController::filterRefunds', 'url' => Url::fromUserInput('/filterremboursement'), 'event' => 'click', //'wrapper' => 'edit-output', 'progress' => [ 'type' => 'throbber', 'message' => t('Verifying entry...'), ], ], );
And i added a route and a controller to handle the request and response:
Routing:
filterRemboursement: path: '/filterremboursement' defaults: _controller: 'Drupal\smeno\Controller\RemboursementsController::filterRefunds' _title: 'filterRemboursement' methods: [POST] requirements: _access: 'TRUE'
Controller:
function filterRefunds(){ dump('HELLO WORLD');die(); }
but this ain’t working as a start.