Jojodae Ganesh Sivaji
March 9, 2012
Views module being shipped with exposed filters feature since version 2.x. It does a great job of adding dynamic and complex filters to a view with no custom code. Filters specific to project needs could be implemented with a few lines of custom code. One such experience is what I would like to share in this blog post.
Since Views 3.x, in addition to filters, sort criteria can be exposed as well. The exposed form can render in a separate block on the sidebar or content top as desired. Though it is one of the improvements, it had limitations when trying to address a requirement specific to our project. I wanted to show the exposed filters and sort forms in different blocks. Such that filter form in the sidebar and sort form in the content top region.
Initially, I attempted to render the block twice; one from standard Drupal block manager and the other from context. And a bit of CSS and jQuery to hide unwanted fields. I thought this worked but later realized that some of the basic usability features and jQuery functions were broken as a result of applying this trick. Also, the markup validity was messed up as the same id was used in both the blocks.
To produce the needed output I had to clone the exposed form, the code I used for the same looks as below,
To above code together with some jQuery snippets made it possible to achieve the desired output. Finding the right functions to clone the view exposed form was a kind of a challenge then. I hope the above snippet would help other developers to tackle similar requirements.
Just like how your fellow techies do.
We'd love to talk about how we can work together
Take control of your AWS cloud costs that enables you to grow!