Timeline for Unlimited Custom Form Fields - Without Ajax
Current License: CC BY-SA 4.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 20, 2019 at 16:35 | answer | added | Prestosaurus | timeline score: 1 | |
Mar 19, 2019 at 16:06 | comment | added | Prestosaurus |
Maybe I need to ask another question. If I implement $form_state->setRebuild(TRUE) via a submit form element, I am not sure how to get the altered/active field value, not the [#default_value] .
|
|
Mar 19, 2019 at 14:30 | comment | added | 4uk4 |
See Examples, when you set $nojs in the ajax examples you get dynamic forms rebuilding without #ajax : cgit.drupalcode.org/examples/tree/ajax_example/src/Form
|
|
Mar 19, 2019 at 13:30 | comment | added | 4uk4 |
To avoid the error use isset() . For dynamic forms in general, try to not submit and save the values until the end. Rebuild the form instead, then check in buildForm() the value of field_number in $form_state and build the dynamic form elements accordingly.
|
|
Mar 19, 2019 at 3:34 | history | edited | Prestosaurus | CC BY-SA 4.0 |
deleted 178 characters in body
|
Mar 19, 2019 at 3:31 | comment | added | Prestosaurus |
The error comes from '#default_value' => $config->get('field')[$i] . So if you have 1 field and add 100, you get 100 notices of undefined offset. Not sure how to get an un-submitted form field value into $form_state as form fields don't have any type of '#onblur' or anything as far as I know. Hoping to add 100+/- fields in one click.
|
|
Mar 19, 2019 at 2:52 | comment | added | Jaypan | Which line is throwing the error? Also note that if you add form elements without Drupal #ajax, you will get an error. When using the form API, you MUST use #ajax to add/remove form fields. There is no other option. | |
Mar 19, 2019 at 0:55 | history | edited | Prestosaurus | CC BY-SA 4.0 |
deleted 52 characters in body
|
Mar 18, 2019 at 18:03 | history | asked | Prestosaurus | CC BY-SA 4.0 |