Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set all sections to be closed using collapsible instead of one remain open #14

Closed
SUTHERLANDesign opened this issue May 22, 2018 · 8 comments
Labels
enhancement New feature or request

Comments

@SUTHERLANDesign
Copy link

At the moment accordions always keep one section open, how to allow for all sections to be be collapsible? is there a way to set the collapsible set to true in the yml file?

@korthjp17
Copy link
Contributor

That is the default behavior of the jQuery UI accordion. You can duplicate the template into your theme/app/mysite folder and swap out the init script to include the collapsible option - https://jqueryui.com/accordion/#collapsible.

<script>
  $( function() {
    $( "#accordion" ).accordion({
      collapsible: true
    });
  } );
</script>

If you want to do a PR for adding that option as something that can be configured with the yml file, we can take a look at it.

@korthjp17 korthjp17 added the enhancement New feature or request label May 23, 2018
@SUTHERLANDesign
Copy link
Author

SUTHERLANDesign commented May 23, 2018

@korthjp17, copy this template, ElementAccordion.ss into my mysite folder? and swap out this line:
<% require javascript('dynamic/silverstripe-elemental-accordion: client/dist/accordion.init.min.js') %>

to this code?

<script>
  $( function() {
    $( "#accordion" ).accordion({
      collapsible: true
    });
  } );
</script>

Correct?

@korthjp17
Copy link
Contributor

That should work. The template file will have to follow the same folder structure as you see in the module though.

For the script, if you are leaving the template as-is for setting up the accordion, use .accordion instead of #accordion

@SUTHERLANDesign
Copy link
Author

@korthjp17, have tired both ways, still not working to get it collapsible. The template is actually working when i use the same folder structure, but collapsible itself it not working.

Also tried to leave the template as it is, and use .accordion, does not work. I also tried to take out the accordion.init.min.js and swap for the code you've given me with #accordion, still doesn't work.

@korthjp17
Copy link
Contributor

Just pulled it down and have it working. You will likely have to create a JS file for the new init script to go in. Silverstripe is including the <script> tag before the <% require %> js lines.

I created a JS file with this code and included it with the <% require %> and it's working.

;(function ($) {
    $(document).on("ready", function () {
        $( ".accordion" ).accordion({
            collapsible: true
        });
    });
})(jQuery);

@SUTHERLANDesign
Copy link
Author

I just did what you suggested, and it is actually working! but every time i visit the page, the first section is still open, but i can close it. Just wanted to have all closed when i visit the page, is that possible to have all closed when visiting the page?

@korthjp17
Copy link
Contributor

It looks like you can set the active option to false - http://api.jqueryui.com/accordion/#option-active

@SUTHERLANDesign
Copy link
Author

Got it working now. Thank you so much. 👍

Here's what i added the active option to be false:

;(function ($) {
    $(document).on("ready", function () {
        $( ".accordion" ).accordion({
            collapsible: true,
            active: false
        });
    });
})(jQuery);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants