Tried to use 'Unlimited' - get error when click Add another item

Created on 30 October 2024, about 2 months ago

Problem/Motivation

I think think this is really cool! I built a custom field type with three parts:
text field - "Training Title"
date filed - "Date completed"
file field - "Upload your certificate"

I set this to be unlimited. It testing it, I found I got the error below when I clicked on the button "Add another item",

D10.3.5
PHP 8.1.29

Maybe a core issue?, but hard for me to tell.

TypeError: Drupal\Core\Form\FormState::setError(): Argument #1 ($element) must be of type array, null given, called in D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Field\WidgetBase.php on line 582 in Drupal\Core\Form\FormState->setError() (line 1155 of D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Form\FormState.php).

#0 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Field\WidgetBase.php(582): Drupal\Core\Form\FormState->setError(NULL, Object(Drupal\Core\StringTranslation\TranslatableMarkup))
#1 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Entity\Entity\EntityFormDisplay.php(277): Drupal\Core\Field\WidgetBase->flagErrors(Object(Drupal\address\Plugin\Field\FieldType\AddressFieldItemList), Object(Symfony\Component\Validator\ConstraintViolationList), Array, Object(Drupal\Core\Form\FormState))
#2 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Entity\ContentEntityForm.php(268): Drupal\Core\Entity\Entity\EntityFormDisplay->flagWidgetsErrorsFromViolations(Object(Drupal\Core\Entity\EntityConstraintViolationList), Array, Object(Drupal\Core\Form\FormState))
#3 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Entity\ContentEntityForm.php(214): Drupal\Core\Entity\ContentEntityForm->flagViolations(Object(Drupal\Core\Entity\EntityConstraintViolationList), Array, Object(Drupal\Core\Form\FormState))
#4 [internal function]: Drupal\Core\Entity\ContentEntityForm->validateForm(Array, Object(Drupal\Core\Form\FormState))
#5 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Form\FormValidator.php(82): call_user_func_array(Array, Array)
#6 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Form\FormValidator.php(274): Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object(Drupal\Core\Form\FormState))
#7 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Form\FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState), 'node_certificat...')
#8 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Form\FormBuilder.php(593): Drupal\Core\Form\FormValidator->validateForm('node_certificat...', Array, Object(Drupal\Core\Form\FormState))
#9 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Form\FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm('node_certificat...', Array, Object(Drupal\Core\Form\FormState))
#10 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Controller\FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\node\NodeForm), Object(Drupal\Core\Form\FormState))
#11 D:\wwwroot\pss-2024-fix\web\core\modules\layout_builder\src\Controller\LayoutBuilderHtmlEntityFormController.php(39): Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#12 [internal function]: Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#13 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#14 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Render\Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#16 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#17 D:\wwwroot\pss-2024-fix\vendor\symfony\http-kernel\HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 D:\wwwroot\pss-2024-fix\vendor\symfony\http-kernel\HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#19 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\StackMiddleware\Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\StackMiddleware\KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\StackMiddleware\ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 D:\wwwroot\pss-2024-fix\web\core\modules\big_pipe\src\StackMiddleware\ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 D:\wwwroot\pss-2024-fix\web\core\modules\page_cache\src\StackMiddleware\PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 D:\wwwroot\pss-2024-fix\web\core\modules\page_cache\src\StackMiddleware\PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 D:\wwwroot\pss-2024-fix\web\core\modules\ban\src\BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\StackMiddleware\ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\StackMiddleware\NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\StackMiddleware\AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\StackMiddleware\StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 D:\wwwroot\pss-2024-fix\web\index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#32 {main}



Steps to reproduce

Follow the steps above.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States goose2000

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @goose2000
  • πŸ‡ΊπŸ‡ΈUnited States goose2000
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    From the stack trace, it looks like you are using layout builder? Could you try same field without layout builder? I havn't seen any issues myself with multi-valued custom fields but layout builder seems to add some other complexities that maybe is messing with the ajax or something.

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    From the stack trace, it looks like you are using layout builder? Could you try same field without layout builder? I havn't seen any issues myself with multi-valued custom fields but layout builder seems to add some other complexities that maybe is messing with the ajax or something.

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    I tried reproducing this with a multi-valued custom field on a block added to layout builder and its working just fine for me. I see in your stacktrace something related to address module it looks like and nothing regarding custom_field module so I would have to assume at this point that the problem is not this module. If you have anything else to add, i'll keep the ticket open for now so you can update but otherwise I'm leaning towards closing since i can't reproduce the issue. Maybe try on another content type without address field and see if you can at least narrow it down.

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    I see you commented on related address module issue so closing this as its unrelated to custom_field. RE: https://www.drupal.org/project/address/issues/3422482 πŸ› Error when we have custom form with ajax Active

  • πŸ‡ΊπŸ‡ΈUnited States goose2000

    Thanks for all this. I have for the time being, set a limit of 5 for my custom field, it works fine.

    I agree something is going on with ajax, and maybe layout builder. The content type this occurs on, does not use layout builder, but yes it is used in other places.

    multi-valued or field set to unlimited ? I'm working with the Unlimited field setting.

    I have not got a chance to test in a fresh or non-layout builder environment yet.

    Closed is fine, I may follow with comments / results later.

Production build 0.71.5 2024