function AjaxAddRemoveElements::addOne
Same name in other branches
- 4.0.x modules/form_api_example/src/Form/AjaxAddRemoveElements.php \Drupal\form_api_example\Form\AjaxAddRemoveElements::addOne()
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\FormCode
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();
}