Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function buildForm(array $form, FormStateInterface $form_state){
- $form = array();
- $form['adherent_id'] = array(
- '#type' => 'email',
- '#prefix' => '<div class="db f5 dark-gray text textinp textinp2">Adherent</div >',
- '#default_value' => '',
- '#required' => TRUE,
- '#autocomplete_route_name' => 'simulation.autocomplete',
- '#attributes' => array(
- 'id' => 'AdherentId',
- 'class' => array('b', 'pa3', 'input-reset', 'ba', 'bg-transparent', 'hover-bg-moon-gray', 'hover-black', 'w-100'),
- ),
- );
- return $form;
- }
- simulation.autocomplete:
- path: '/simulator/autocomplete'
- defaults:
- controller: 'DrupalsmenoControllerAdminController::autocomplete1'
- requirements:
- _access: 'TRUE'
- <?php
- namespace DrupalsmenoController;
- use DrupalCoreControllerControllerBase;
- use SymfonyComponentHttpFoundationRequest;
- use SymfonyComponentHttpFoundationJsonResponse;
- class AdminController extends ControllerBase {
- function autocomplete1(request $request){
- $typed_category = $request->query->get('q');
- $matches = [
- '0' => 'user@mail.com',
- '1' => 'nina@mail.com',
- '2' => 'pierre-jr@mail.com'
- ];
- return new JsonResponse($matches);
- }
- }
Add Comment
Please, Sign In to add comment