New layout view -- accordian does not auto-close after response | XM Community
Skip to main content
Question

New layout view -- accordian does not auto-close after response


Forum|alt.badge.img+3

Does anyone know how to auto-close matrix, accordian-style questions in the new layout view? (There doesn’t seem to be a th[id] element.)

Thanks for any ideas!

3 replies

Nanditha MM
Level 4 ●●●●
Forum|alt.badge.img+14
  • Level 4 ●●●●
  • 101 replies
  • April 25, 2024

Hi @Chipper ,

In Qualtrics, the new layout view might not have a straightforward way to auto-close matrix questions with accordion-style formatting. You can give a try with JavaScript

//JavaScript//

Qualtrics.SurveyEngine.addOnload(function() {
    // Function to collapse all matrix questions initially
    function collapseMatrixQuestions() {
        var matrixQuestions = document.querySelectorAll('.MatrixQuestion');
        matrixQuestions.forEach(function(question) {
            var accordionToggle = question.querySelector('.AccordionContent');
            if (accordionToggle) {
                accordionToggle.click(); // Simulate a click on the accordion toggle to collapse the question
            }
        });
    }

    // Call the function to collapse matrix questions on page load
    collapseMatrixQuestions();
});

 

Thank you!


Forum|alt.badge.img+3
  • Author
  • Level 1 ●
  • 10 replies
  • April 25, 2024

Hi, @Nanditha MM,

Thanks so much for providing the script! Unfortunately, I think there’s something in this style that prevents your and my scripts from working.

I am grateful for your generosity!

 


Forum|alt.badge.img

For anyone looking, this is how we handled auto-close matrix accordion-style questions in the newer Simple layout (using jQuery):

Qualtrics.SurveyEngine.addOnReady(function()
{
	/*Place your JavaScript here to run when the page is fully displayed*/

    // Attach a click event to all elements with the class 'grid-cell.accordion'
    $('.grid-cell.accordion').on('click', function() {
	    let matrixStatement = $(this).closest('.matrix-statement');
	    matrixStatement.find('.matrix-statement-header').trigger('click');
    });

});

 


Leave a Reply