-3

hope someone can help, I have a jQuery ui accordion working OK, but I cannot get any options I set to work. I'm not using modules for this, adding jQuery UI in my library, and the accordion itself works so I know all scripts are loading OK. My library file has:

ui-accordion:
  version: 1.x
  js:
    js/site/min/jqui-accordion-min.js: {}
  dependencies:
    - core/drupal
    - core/drupalSettings
    - core/jquery
    - core/jquery.ui.accordion

The library is then attached in a template file. My jqui-accordion-min.js has:

(function ($, Drupal) {
  Drupal.behaviors.basic = {
    attach: function (context, settings) {
        $("#accordion" ).accordion({ heightStyle: "content" });
    }
  };
}(jQuery, Drupal));

I've tried other options too, including autoHeight: "false".

Is there something wrong with my jQuery, or do I need to load something else?

0

OK found the answer here - I only had part of the option set correctly; here's the full jQuery:

(function ($, Drupal) {
  Drupal.behaviors.basic = {
    attach: function (context, settings) {
        $("#accordion" ).accordion({ 
            heightStyle: "content"  
        });

        // Getter
        var heightStyle = $( "#accordion" ).accordion( "option", "heightStyle" );

        // Setter
        $( "#accordion" ).accordion( "option", "heightStyle", "content" );
    }
  };
}(jQuery, Drupal));

My bad for skim-reading the API, I saw 'Initialize the accordion' then 'Or set...' (and so ignored the next bit) instead of 'Get or Set'. Wasn't clear if the 'or' means you could use the 'getter' or the 'setter' instead. But I used both as written and it works now. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.