New answers tagged

1

This issue is usually -- but not always -- because someone has written Javascript without adding semicolons in the appropriate places. JS is valid without them but only when there is also a line-end at that point. Many JS preprocessors remove line breaks, so making the JS invalid. This can be resolved by examining the JS source for missing semicolons and ...


1

I don't think you can force javascript to only run once. In addition to big pipe, any lazy loader, ajax form update (consider entity reference fields), or other ajax functionality on the page can trigger javascript to run again. This is the issue that jQuery.once() addresses, and the reason it is used. It adds a class on the element, then executes on ...


0

In drupal 8 you might have to add core/drupal as a dependency of your module. your-custom-module: version: 1.x js: js/your_custom_module.js: {} dependencies: - core/drupal - core/drupalSettings


0

So Leymannx was right about the dist folder version of Google Materialize. I had downloaded the framework directly from their get started page. I thought it was the same files, everything else worked, even when I just created a simple index.html on my local server, the simple sidenav() worked. For the heck of it and being completely out of ideas, I did a ...


1

You'll want to use the latest dev version of jQuery update, 7.x-3.x-dev to get the latest version of jQuery, or at least jQuery 3.1. See this drupal issue for more insight. You can see in the 7.x-3.x dev branch, it has jQuery 3.1. Note, there is also a patch for jQuery 3.2, 3.3, and 3.4 against the 7.x-2.7 branch.


1

$ is a shortcode for jQuery, does your layout.js contain just $('.sidenav').sidenav(); Maybe try (function ($, Drupal) { $('.sidenav').sidenav(); })(jQuery, Drupal); You can read more here: https://www.drupal.org/docs/8/api/javascript-api/javascript-api-overview


0

This works as designed. Behaviors attach runs multiple times, but the scope provided in context changes. So check if the element is in context and apply once() to get the element only one time: Drupal.behaviors.js_mod = { attach: function attach(context, settings) { var $myradar = $(context).find('#drupal-myradar').once('js_mod'); if ($...


0

The solution above is for Drupal 7. In Drupal 8, hook_views_ajax_data_alter is deprecated and was replaced by hook_ajax_render_alter. For those of you looking for it, here is how to do it in Drupal 8 (source here). function YOURMODULE_ajax_render_alter(array &$data) { foreach ($data as $key => $command) { if ($command['command'] === '...


1

There are a few items worth mentioning here. The first is that you'll want to avoid making modifications to existing modules and themes. For your use case, it would be better to create a new theme of your own and use Bootstrap as the base theme. Here is a good link to get you started: https://www.drupal.org/docs/8/theming-drupal-8/creating-a-drupal-8-sub-...


3

When attached make sure to use the correct name of the "library" Inside your mymodule.libraries.yml file. The first line is your library name. I use a different name inside my library file, and I attached a wrong library name. function mymodule_preprocess_block(&variables){ $variables['#attached']['library'][] = 'mymodule/mylibraryname'; ...


2

In Case if your library called mymodule, then attached shoud be as i described below function mytheme_preprocess_block(&$variables) { if ($variables['elements']['#id'] == 'myblock') { $variables['#attached']['library'][] = 'module_name/mymodule'; } }


Top 50 recent answers are included