Office Hours Exceptions Widget "Add exception" button adds 2 rows

Created on 11 August 2025, about 2 months ago

When creating a new office hours field with exceptions, the "Add exception" AJAX button behaves incorrectly:

  • Initial state: 0 exception rows
  • First click: Adds 1 row correctly → total: 1 row
  • Second click: Adds 2 rows instead of 1 → total: 3 rows (should be 2 instead)
  • Third click and beyond: Adds 1 row correctly

The issue only occurs on the second click - it adds double the expected number of rows.

I've spent considerable time debugging this but haven't been able to identify the root cause. The problem seems to be in the OfficeHoursExceptionsWidget AJAX handling, but I'm running out of ideas on what could be causing this specific behavior. At the time the AJAX callback is triggered, the element seems to have more slots that it should.

Environment:

Drupal 10.4.7
Office Hours module (exceptions widget)

Steps to reproduce:

  • Create/edit a node with Office Hours field (exceptions enabled)
  • Click "Add exception" → 1 row appears
  • Click "Add exception" again → 3 total rows appear (should be 2)
🐛 Bug report
Status

Active

Version

1.28

Component

Code - widget

Created by

🇧🇪Belgium bernardopaulino Brussels

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

Merge Requests

Comments & Activities

  • Issue created by @bernardopaulino
  • 🇳🇱Netherlands johnv

    Indeed, this is a known bug. Not sure how to solve this, either.

  • 🇮🇳India divyansh.gupta Jaipur

    Working on it!

  • 🇮🇳India divyansh.gupta Jaipur

    I was able to reproduce the bug and had created a MR which resolved the bug for me,
    Please review

  • Pipeline finished with Success
    about 1 month ago
    Total: 420s
    #582711
  • 🇳🇱Netherlands johnv

    Thank you, but is is not correctly working when the entity already as 1 or more exceptions saved.

  • 🇮🇳India divyansh.gupta Jaipur

    Made some changes and now things are working perfectly fine on my local.
    Please review.

  • Pipeline finished with Success
    about 1 month ago
    #583882
  • 🇳🇱Netherlands johnv

    Thank you for your efforts. Please see my attached patch (sorry for not using MR).

    That patch only contains a one-line change (thanks to your efforts, though).
    Please review, and

    [stat preparations]
    - set 'number of slorts per day' to 3;
    - edit node, add 2 exceptions and save.
    [start test]
    - edit node again,
    - add exception, 3 times
    - fill 2nd exception with 1 or more timeslots,
    - add exception, --> too many slots are added.

    Does that happen with your patch, too?
    Even if so, i guess that can be considered as an edge case we can leave alone.

    Regarding your patch:
    - please do not rename variables, it makes the patch harder to understand.
    - the fallback to NULL, do you encounter an erroro if not, in if (($dv['day'] ?? NULL) !== 'exception_day_delta') { ?
    - teh check for array, do you encounter an arrray if not, in if (is_array($default_values)) { ?

  • Pipeline finished with Success
    about 1 month ago
    Total: 254s
    #584160
  • 🇮🇳India divyansh.gupta Jaipur

    @johnv,
    i have updated my MR to make minimal variable changes and i was able to reproduce the error but by these following steps:

    • Set Number of slots per day to 3.
    • Create a node with an Office Hours field (exceptions enabled).
    • Add 2 exceptions and save.

    Now edit the node again:

    • Click “Add exception” 3 times → 3 new empty rows appear.
    • Fill the 2nd exception with one or more timeslots.
    • Click “Add exception” again → too many rows are added (2 instead of 1).
    • Further clicks only add one row at a time.

    I also tested your patch, but I still ran into the original behavior described in the issue. It’s possible I may have missed a configuration detail on my side — just wanted to share my findings.
    Can you also please review my latest changes.

    • johnv committed 1231fb81 on 8.x-1.x
      Issue #3540739 by divyansh.gupta: Office Hours Exceptions Widget 'Add...
  • 🇳🇱Netherlands johnv

    Thanks a lot. This was a long time annoying bug.
    The resulting patch also prevents 'null' records to be coming in.

Production build 0.71.5 2024