3 namespace Drupal\ajax_forms_test\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Form builder: Builds a form that triggers a simple AJAX callback.
11 class AjaxFormsTestLazyLoadForm extends FormBase {
16 public function getFormId() {
17 return 'ajax_forms_test_lazy_load_form';
23 public function buildForm(array $form, FormStateInterface $form_state) {
24 // We attach a JavaScript setting, so that one of the generated AJAX
25 // commands will be a settings command. We can then check the settings
26 // command to ensure that the 'currentPath' setting is not part
27 // of the Ajax response.
28 $form['#attached']['drupalSettings']['test'] = 'currentPathUpdate';
29 $form['add_files'] = [
30 '#title' => $this->t('Add files'),
31 '#type' => 'checkbox',
32 '#default_value' => FALSE,
36 '#value' => $this->t('Submit'),
38 'wrapper' => 'ajax-forms-test-lazy-load-ajax-wrapper',
39 'callback' => 'ajax_forms_test_lazy_load_form_ajax',
41 '#prefix' => '<div id="ajax-forms-test-lazy-load-ajax-wrapper"></div>',
50 public function submitForm(array &$form, FormStateInterface $form_state) {
51 $form_state->setRebuild();