Filterable FAQ
Traditional FAQs suck. A long list of questions is simply not digestible and don't really help your users. If you don't have resources to develop a massive search engine that queries a database of resources and questions, then this simple filtering technique might be for you!
Using Bootstrap's Collapsible Panels and a little JQuery, I put together this simple, searchable FAQ:
At the core of all this is JQuery's filter() function that accepts an anonymous function where we only return .panel elements that contain a match to our filter string.
Step by step
- Watch the
#filtertext box forkeyupevents - Put that filter string into a
RegExpusing theiparameter flag to ignore case (so we can easily compare great swaths of text with our filter). - Select all panels in the searchable area using
$('.searchable .panel') - Run the
filter()function on all of the panels to only select questions that contain the filter string we specified. - Give the filter function an anonymous function that uses
RegExp.test()to check for matches on only the text within each panel and return only panel elements that have a match. - Show only those panels!
Gotta have that feel-good UX
In order to give the users some feedback as they're searching, I do two things:
-
First, I use Bootstrap's form-group and associated classes
.has-successand.has-errorto change the color of the form based on the current result of the filter. -
I have a small message that I keep updating to inform the user of the result.
Hope someone at some point somewhere found this useful!
Thank you Dr. Who for inspiring my sample questions. And thank you Hipsum for providing me filler text that never ceases to make me laugh.