Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Adding jQuery UI Widget to drupal 8

By editor , 8 December, 2016
Question

How to Add a jQuery ui Widget to drupal 8 page / module ?

Example :

Step 1 : Add libraries. Example: (With theme / or module : mytheme)

On : mytheme.libraries.yml file

mylibrary:
  version: 1.x
  js:
    js/script.js: {}
  dependencies:
    - core/drupal
    - core/jquery
    - core/jquery.ui.tabs

    
Step 2 : Attache this mylibrary
Methode 1. On a theme: Add to mytheme.info.yml file
libraries:
  - mytheme/mylibrary

 
Methode 2. On a custom page or block
$output['#attached']['library'][] = 'mytheme/mylibrary';

Step 3 : Create js/script.js file (Here an example of Tabs)

(function ($, Drupal, window, document) {
  Drupal.behaviors.basic = {
    attach: function (context, settings) {
      $(window).load(function () {
        $("#tabs").tabs();
      });
    }
  };

}(jQuery, Drupal, this, this.document));

Step 4 : Insert your jQuery UI codes to the appropriated page.

Tags

  • Drupal 8
  • Code
  • jQuery
Drupal Behaviors - JavaScript and jQuery
Add JavaScript to a module

Comments

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer