Error when date field is left blank

Created on 11 May 2023, over 1 year ago
Updated 17 May 2023, over 1 year ago

Problem/Motivation

When leaving a date blank in exception days, the error message displays on every element.

Steps to reproduce

Have an office hours field with exception hours. Add a few exception dates and leave one of the dates for that exception blank and submit the form. The validation will place a box, or if you use inline errors module the error message, on all the date fields. See the screenshots below.

Proposed resolution

I am trying to find a fix but I am unable to find the place where this gets set, could use some expertise.

🐛 Bug report
Status

Fixed

Version

1.8

Component

Code - widget

Created by

🇨🇦Canada ebremner

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

Comments & Activities

  • Issue created by @ebremner
  • 🇳🇱Netherlands johnv

    Indeed.
    System also generates the error "Error message: This value should be of the correct primitive type."

    The catching is done in OfficeHoursBaseSlot~validateOfficeHoursSlot()
    Perhaps adding an override in OfficeHoursExceptionsSlot for this field.

    Please note that the data should have been properly formatted in valueCallback() function.
    (Please use today's dev-version, as I refactored stuff to adheere better to implementation pattern - see recent 2 issues.)

  • 🇮🇳India Raveen Kumar

    @johnv, This seems to be a kind of validation. Whenever we submit any forms, if we remains any fields empty, the whole field (*required) throws an error message on every element on the form. This might be system behavior for showing all fields required.

  • 🇮🇳India mukhtarm

    Using today's dev version and when saving the office hours field throws error as follows:

    TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, class Drupal\office_hours\Element\OfficeHoursDatelist does not have a method "processOfficeHoursSlot" in call_user_func_array() (line 1010 of /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php)
    #0 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1010): call_user_func_array(Array, Array)
    #1 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1073): Drupal\Core\Form\FormBuilder->doBuildForm('field_config_ed...', Array, Object(Drupal\Core\Form\FormState))
    #2 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1073): Drupal\Core\Form\FormBuilder->doBuildForm('field_config_ed...', Array, Object(Drupal\Core\Form\FormState))
    #3 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1073): Drupal\Core\Form\FormBuilder->doBuildForm('field_config_ed...', Array, Object(Drupal\Core\Form\FormState))
    #4 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1073): Drupal\Core\Form\FormBuilder->doBuildForm('field_config_ed...', Array, Object(Drupal\Core\Form\FormState))
    #5 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1073): Drupal\Core\Form\FormBuilder->doBuildForm('field_config_ed...', Array, Object(Drupal\Core\Form\FormState))
    #6 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(577): Drupal\Core\Form\FormBuilder->doBuildForm('field_config_ed...', Array, Object(Drupal\Core\Form\FormState))
    #7 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(323): Drupal\Core\Form\FormBuilder->processForm('field_config_ed...', Array, Object(Drupal\Core\Form\FormState))
    #8 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\field_ui\Form\FieldConfigEditForm), Object(Drupal\Core\Form\FormState))
    #9 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
    #10 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #11 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #12 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #13 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #14 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #15 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #16 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #17 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #18 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #19 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #20 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #22 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #23 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(713): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #24 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #25 {main}

    @johnv just FYI

  • 🇮🇳India mukhtarm

    I cleared the cache and resubmitted the form and it saved now!
    FYI i upgraded from ("^1.7") to today's dev version("1.x-dev@dev") directly.

  • 🇮🇳India mukhtarm

    on comment #2
    I think the error is throwing from the core, due to a formatting.when doing OfficeHoursItem::formatValue for excempted values.
    This is mentioned in "src/Plugin/Field/FieldType/OfficeHoursItem.php" itself #226
    // Cast the time to integer, to avoid core's error
    // "This value should be of the correct primitive type."

    I think a casting needed for empty values in the exempted slots

    • johnv committed 655e3d8e on 8.x-1.x
      Issue #3359690: Error when date field is left blank
      
  • Status changed to Fixed over 1 year ago
  • 🇳🇱Netherlands johnv

    Thanks,
    I was working on this while you were commenting. Please check the new code.
    The problem also occurred on the 'normal' basic list widget.

  • 🇳🇱Netherlands johnv

    A problem with empty records.

    • johnv committed b8d83449 on 8.x-1.x
      Issue #3359690: Error when date field is left blank
      
  • Status changed to Needs work over 1 year ago
  • 🇳🇱Netherlands johnv

    There is an error in the naming of a class. a small character is used, instead of a capital character, resulting in 🐛 WSOD for OfficeHoursExceptionsSlot since update to 8.x-1.8+dev Fixed

    • johnv committed 417d6e31 on 8.x-1.x
      Issue #3359690: Error when date field is left blank
      
  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024