function AjaxTestFocusFirstForm::buildForm

Same name and namespace in other branches
  1. 10 core/modules/system/tests/modules/ajax_test/src/Form/AjaxTestFocusFirstForm.php \Drupal\ajax_test\Form\AjaxTestFocusFirstForm::buildForm()
  2. 11.x core/modules/system/tests/modules/ajax_test/src/Form/AjaxTestFocusFirstForm.php \Drupal\ajax_test\Form\AjaxTestFocusFirstForm::buildForm()

Overrides FormInterface::buildForm

File

core/modules/system/tests/modules/ajax_test/src/Form/AjaxTestFocusFirstForm.php, line 27

Class

AjaxTestFocusFirstForm
Form for testing AJAX FocusFirstCommand.

Namespace

Drupal\ajax_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $form['first_input'] = [
        '#type' => 'textfield',
    ];
    $form['second_input'] = [
        '#type' => 'textfield',
    ];
    $form['a_container'] = [
        '#type' => 'container',
        '#attributes' => [
            'id' => 'a-container',
        ],
    ];
    $form['a_container']['first_container_input'] = [
        '#type' => 'textfield',
    ];
    $form['a_container']['second_container_input'] = [
        '#type' => 'textfield',
    ];
    $form['focusable_container_without_tabbable_children'] = [
        '#type' => 'container',
        '#attributes' => [
            'tabindex' => '-1',
            'id' => 'focusable-container-without-tabbable-children',
        ],
        '#markup' => 'No tabbable children here',
    ];
    $form['multiple_of_same_selector_1'] = [
        '#type' => 'container',
        '#attributes' => [
            'id' => 'multiple-of-same-selector-1',
            'class' => [
                'multiple-of-same-selector',
            ],
        ],
    ];
    $form['multiple_of_same_selector_1']['inside_same_selector_container_1'] = [
        '#type' => 'textfield',
    ];
    $form['multiple_of_same_selector_2'] = [
        '#type' => 'container',
        '#attributes' => [
            'id' => 'multiple-of-same-selector-2',
            'class' => [
                'multiple-of-same-selector',
            ],
        ],
    ];
    $form['multiple_of_same_selector_2']['inside_same_selector_container_2'] = [
        '#type' => 'textfield',
    ];
    $form['nothing_tabbable'] = [
        '#type' => 'container',
        '#attributes' => [
            'id' => 'nothing-tabbable',
        ],
        '#markup' => 'nothing tabbable',
    ];
    $form['nothing_tabbable']['nested'] = [
        '#type' => 'container',
        '#markup' => 'There are divs in here, but nothing tabbable',
    ];
    $form['focus_first_in_container'] = [
        '#type' => 'submit',
        '#value' => 'Focus the first item in a container',
        '#name' => 'focusFirstContainer',
        '#ajax' => [
            'callback' => '::focusFirstInContainer',
        ],
    ];
    $form['focus_first_in_form'] = [
        '#type' => 'submit',
        '#value' => 'Focus the first item in the form',
        '#name' => 'focusFirstForm',
        '#ajax' => [
            'callback' => '::focusFirstInForm',
        ],
    ];
    $form['uses_selector_with_multiple_matches'] = [
        '#type' => 'submit',
        '#value' => 'Uses selector with multiple matches',
        '#name' => 'SelectorMultipleMatches',
        '#ajax' => [
            'callback' => '::focusFirstSelectorMultipleMatch',
        ],
    ];
    $form['focusable_container_no_tabbable_children'] = [
        '#type' => 'submit',
        '#value' => 'Focusable container, no tabbable children',
        '#name' => 'focusableContainerNotTabbableChildren',
        '#ajax' => [
            'callback' => '::focusableContainerNotTabbableChildren',
        ],
    ];
    $form['selector_has_nothing_tabbable'] = [
        '#type' => 'submit',
        '#value' => 'Try to focus container with nothing tabbable',
        '#name' => 'SelectorNothingTabbable',
        '#ajax' => [
            'callback' => '::selectorHasNothingTabbable',
        ],
    ];
    $form['selector_does_not_exist'] = [
        '#type' => 'submit',
        '#value' => 'Call FocusFirst on selector that does not exist.',
        '#name' => 'SelectorNotExist',
        '#ajax' => [
            'callback' => '::selectorDoesNotExist',
        ],
    ];
    $form['#attached']['library'][] = 'ajax_test/focus.first';
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.