Uncaught ReferenceError: Modernizr is not defined at timeslots.js

Created on 15 February 2024, over 1 year ago

Problem/Motivation

Uncaught ReferenceError: Modernizr is not defined at timeslots.js

When you load the timeslot widget on the order information page you get the above error.

I don't see that modernizer is loaded in the script

Maybe load it via a cdn?

<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
πŸ› Bug report
Status

Active

Version

1.1

Component

Code

Created by

πŸ‡ΏπŸ‡¦South Africa vlooi vlerke

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

Merge Requests

Comments & Activities

  • Issue created by @vlooi vlerke
  • πŸ‡ΏπŸ‡¦South Africa vlooi vlerke

    Removing the call for Modernizer reveals more errors

    Uncaught TypeError: $context.find(...).once is not a function

    line 30: $context.find('input[data-drupal-date-format]').once('datePicker').each(function ()

    And

    Uncaught TypeError: $(...).find(...).findOnce is not a function

    Line:99 $(context).find('input[data-drupal-date-format]').findOnce('datePicker').datepicker('destroy');

    Remove jQuery dependency from the once feature β†’

  • Status changed to Needs review about 1 year ago
  • πŸ‡ΏπŸ‡¦South Africa vlooi vlerke

    To Fix: Uncaught ReferenceError: Modernizr is not defined at timeslots.js

    Add:

    timeslots:
      js:
        js/timeslots.js: {}
      css:
        theme:
          css/timeslots.css: {}
      dependencies:
        - core/jquery
        - core/drupal.date
     +  - core/modernizr
        - jquery_ui_datepicker/datepicker
    

    To: commerce_timeslots.libraries.yml

    Clear cache.

    This will fix the error but the next error will apper

    Uncaught TypeError: $context.find(...).once is not a function

  • πŸ‡ΏπŸ‡¦South Africa vlooi vlerke

    to get rid of

    Uncaught TypeError: $context.find(...).once is not a function

    change line 30:

    $context.find('input[data-drupal-date-format]').once('datePicker').each(function ()

    to

    $(once('input[data-drupal-date-format]', 'datePicker', context.find)) .each(function () {
    

    This removes the error but it is not fixing the issue. Date picker is not loaded and a user can not select a date.

    tried adding - core/once as a dependency but did not work

  • πŸ‡ΊπŸ‡ΈUnited States generalredneck Texas, USA πŸ‡ΊπŸ‡Έ

    Additionally... based on https://www.drupal.org/node/3333253 β†’ Modernizer library is deprecated as of Drupal 10.1.0.

  • πŸ‡ΊπŸ‡ΈUnited States generalredneck Texas, USA πŸ‡ΊπŸ‡Έ

    The other issues are going to be a part of https://www.drupal.org/node/3158256 β†’ . Back in 9.2.0 Drupal core deprecated jquery once and the BC layer was removed from Drupal 10 completely.

    I'm going to try and get a patch/mr in place. Moving this to Needs work as there is no patch or MR to review currently.

  • πŸ‡ΊπŸ‡ΈUnited States generalredneck Texas, USA πŸ‡ΊπŸ‡Έ

    Ugh, Javascript isn't my strong point. I'm really a backend developer.

    I've managed to get rid of the errors, but I don't know how it's SUPPOSED to work.

    There's no input field with data-drupal-date-format. So the datepicker isn't getting instantiated and the ajax calls aren't being hit on the date change...

    I'm going to have to let someone else work on this part. I'm pushing up what I've done so far.

  • πŸ‡ΊπŸ‡ΈUnited States generalredneck Texas, USA πŸ‡ΊπŸ‡Έ

    I believe what I may have been experiencing while working on this issue is related to ✨ Timeslot Widget does not update after a new date is set Active ...

    We may have to break it down to see what we can get working... still JS work... still not my wheelhouse :/

  • πŸ‡ΊπŸ‡ΈUnited States generalredneck Texas, USA πŸ‡ΊπŸ‡Έ

    Alright... I can confirm that the data-drupal-date-format attribute is no longer being added to the date field for what ever reason. My quick fix for this is to FORCE the attribute to be set to a fixed value. this specific piece was reported in ✨ Timeslot Widget does not update after a new date is set Active . That said, there was ALSO the 2 deprecations of Jquery Once and Modernizr. I've fixed the code so that it implements the recommendations based on the documentation at https://www.drupal.org/node/3158256 β†’ . The comments above had the arguments swapped... therefore, my first commits to this MR did as well.

    I've got the date picker working again as you can see in the screenshot and the dropdowns change value.

  • πŸ‡²πŸ‡©Moldova andrei.vesterli Chisinau

    Hey @generalredneck, left a few comments, the rest is just perfect! Can you please address those so i can merge the MR and move forward?
    p.s. i want to prepare a new release that will include these last merged MRs into the dev branch.

  • πŸ‡²πŸ‡©Moldova andrei.vesterli Chisinau
  • πŸ‡ΊπŸ‡ΈUnited States generalredneck Texas, USA πŸ‡ΊπŸ‡Έ

    Makes sense. I didn't know there was a suggested changes feature in Gitlab... Neat. I applied them.

    I want you to make a release too so I can continue working on McGreen Acres ecommerce solution! πŸ˜‚

    I put in a bunch of work just to try this thing out and I think it's gonna pay off!

  • Pipeline finished with Skipped
    2 days ago
    #498420
  • πŸ‡²πŸ‡©Moldova andrei.vesterli Chisinau

    Heh....I am here for some support ;). I wrote this module a while ago...Don't have much time to support/maintain it but if it may help with your project, good luck man! You've done a lot already!

    Yeah, I will push a new release to stabilize things around.

  • πŸ‡²πŸ‡©Moldova andrei.vesterli Chisinau
  • πŸ‡²πŸ‡©Moldova andrei.vesterli Chisinau
Production build 0.71.5 2024