You are here

public function AjaxAddRemoveElements::addOne in Examples for Developers 3.x

Submit handler for the "add-one-more" button.

Increments the max counter and causes a rebuild.

File

modules/form_api_example/src/Form/AjaxAddRemoveElements.php, line 131

Class

AjaxAddRemoveElements
Example ajax add remove buttons.

Namespace

Drupal\form_api_example\Form

Code

public function addOne(array &$form, FormStateInterface $form_state) {
  $num_field = $form_state
    ->get('num_lines');
  $add_button = $num_field + 1;
  $form_state
    ->set('num_lines', $add_button);
  $form_state
    ->setRebuild();
}