Filters are used to apply filtered search results, either via a standard form GET, or asynchronously via a javascript event callback.
Filters get pre-populated based on the selection on page load, they also get pre-populated to the object that is sent to the server as ajax request.
Multi-select filters use hidden checkboxes to select filters to apply.
The link wrapping the checkbox has several data attributes and an href
that must be applied:
// href // This should be the filter slug path that will be used by bot user agents.
// data-filter-anchor // This is used by the js to target anchors".
The containing <ul>
also requires a data-category
set to the category slug value and a
data-filter-category-container
attribute.
The new Filters use the Collapsible feature which is a part of the PL in the content modules section and puts all the filter inside the collapsible headings
Both the multi-select and single select filters are handled similarly as in they both have the same attributes applied.
Below is the partial template used for these filter inputs inside a loop:
<% if custom_template === false %>
<a href="/<%= filter_slug %>" data-filter-anchor>
<input type="<%= type %>"
class="hide" id="filter-input-<%= filter_id %>" name="<%= category_slug %>"
value="<%= filter_slug %>"
<%=custom_input_attr%>
<%=filter_slug === 'none' ? 'checked' : ''%>
/>
<label class="<%= type %>-label <%= type %>-label-left" for="filter-<%= filter_id %>">
<span class="fake-<%= type %> icon icon-<%= type %>"></span>
<%= filter_name %>
</label>
</a>
<% end %>
Below is an example of local variables passed on to the above partial:
<%= partial('_partials/_filters_2/filters_input',
:locals => { :category_slug => f[:slug],
:filter_slug => t[:slug],
:filter_id => t[:id],
:filter_name => t[:name],
:is_radio => f[:is_radio],
:type => f[:is_radio] ? "radio" : "checkbox",
:custom_template => false,
:custom_input_attr => ''
})
%>
Note: The custom_input_attr
is used for custom cases, for instance if you pass a value of data-no-selection
to
it, the input will not be considered as a selection even if it is selected. This is useful in case of "None" selections.
This input will be discounted from all the input counts as well.
Color selection filters are custom type and use a flag in the ruby object custom_type: "color"
which is used by the loop to determine which code to output.
Below is a partial example for a color selection input
<% if custom_template === 'color' %>
<a href="/<%= filter_slug %>" data-filter-anchor>
<input type="checkbox" class="hide" id="<%= filter_id %>" value="<%= filter_slug %>" name="<%= category_slug %>" checked>
<label class="checkbox" for="<%= filter_id %>"></label>
</a>
<% end %>
Below is an example of locals passed to the partial:
<%= partial('_partials/_filters_2/filters_input',
:locals => { :category_slug => f[:slug],
:filter_slug => t[:slug],
:filter_id => t[:id],
:filter_name => t[:name],
:is_radio => f[:is_radio],
:type => f[:is_radio] ? "radio" : "checkbox",
:random_number => random_number,
:custom_template => 'color',
:custom_input_attr => ''
})
%>
The filters are responsive and work on the <768 and >768 breakpoints for mobile and desktop respectively.
<div class="container container-flush">
<h1 id="filters-doc" style="margin-bottom:50px;">Filters v2.0</h1>
<div class="col-lg-4 col-md-4 col-sm-12 filters-form-container">
<form accept-charset="UTF-8" action="/marketplace/vendors" method="get" data-async="" data-filters-form="">
<div data-filter-actions="">
<p data-cta-filter-count="">Filters</p>
<hr>
<div class="row-col-xs-6 row cta-button-row">
<div class="col-xs-6">
<a class="btn btn-primary btn-block" href="#" data-apply="" disabled="disabled">
<span class="filters-apply-text">Apply</span>
</a>
</div>
<div class="col-xs-6">
<a class="btn btn-alternate btn-block" href="#" data-clear="">
Clear
</a>
</div>
</div>
</div>
<div class="panel-group" id="filters-accordion" data-filters-accordion="">
<div class="panel">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#filters-accordion" href="#train-length-radio-filters" class="collapsed">
<h2 class="panel-title">
Train Length
<span class="content value" data-selected-filters="">Any</span>
</h2>
</a>
</div>
<div id="train-length-radio-filters" class="panel-collapse collapse filter-panel">
<ul class="xs-lg-divider list-unstyled panel-body" data-category="train-length-radio-filters" data-filter-category-container="">
<li data-display-id="none-radio">
<a href="/none" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-8632" name="train-length-radio-filters" value="none" data-no-selection="" checked="">
<label class="radio-label radio-label-left" for="filter-8632">
<span class="fake-radio icon icon-radio"></span>
None
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/cathedral" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-123" name="train-length-radio-filters" value="cathedral">
<label class="radio-label radio-label-left" for="filter-123">
<span class="fake-radio icon icon-radio"></span>
Cathedral
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/chapel" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-456" name="train-length-radio-filters" value="chapel">
<label class="radio-label radio-label-left" for="filter-456">
<span class="fake-radio icon icon-radio"></span>
Chapel
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/court" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-789" name="train-length-radio-filters" value="court">
<label class="radio-label radio-label-left" for="filter-789">
<span class="fake-radio icon icon-radio"></span>
Court
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/semi-cathedral" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-7891011" name="train-length-radio-filters" value="semi-cathedral">
<label class="radio-label radio-label-left" for="filter-7891011">
<span class="fake-radio icon icon-radio"></span>
Semi-Cathedral
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/sweep" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-789101112" name="train-length-radio-filters" value="sweep">
<label class="radio-label radio-label-left" for="filter-789101112">
<span class="fake-radio icon icon-radio"></span>
Sweep
</label>
</a>
</li>
</ul>
</div>
</div>
<div class="panel">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#filters-accordion" href="#wedding-categories-checkbox-filters" class="collapsed">
<h2 class="panel-title">
Wedding Categories
<span class="content value" data-selected-filters="">Any</span>
</h2>
</a>
</div>
<div id="wedding-categories-checkbox-filters" class="panel-collapse collapse filter-panel">
<ul class="xs-lg-divider list-unstyled panel-body" data-category="wedding-categories-checkbox-filters" data-filter-category-container="">
<li data-display-id="1804">
<a href="/bar-drinks" data-filter-anchor="">
<input type="checkbox" class="hide" id="filter-input-012" name="wedding-categories-checkbox-filters" value="bar-drinks">
<label class="checkbox-label checkbox-label-left" for="filter-012">
<span class="fake-checkbox icon icon-checkbox"></span>
Bar + Drinks
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/beauty" data-filter-anchor="">
<input type="checkbox" class="hide" id="filter-input-345" name="wedding-categories-checkbox-filters" value="beauty">
<label class="checkbox-label checkbox-label-left" for="filter-345">
<span class="fake-checkbox icon icon-checkbox"></span>
Beauty
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/cakes-desserts" data-filter-anchor="">
<input type="checkbox" class="hide" id="filter-input-678" name="wedding-categories-checkbox-filters" value="cakes-desserts">
<label class="checkbox-label checkbox-label-left" for="filter-678">
<span class="fake-checkbox icon icon-checkbox"></span>
Cakes + Desserts
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/decorations-accents" data-filter-anchor="">
<input type="checkbox" class="hide" id="filter-input-6789" name="wedding-categories-checkbox-filters" value="decorations-accents">
<label class="checkbox-label checkbox-label-left" for="filter-6789">
<span class="fake-checkbox icon icon-checkbox"></span>
Decorations + Accents
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/destination-weddings" data-filter-anchor="">
<input type="checkbox" class="hide" id="filter-input-67810" name="wedding-categories-checkbox-filters" value="destination-weddings">
<label class="checkbox-label checkbox-label-left" for="filter-67810">
<span class="fake-checkbox icon icon-checkbox"></span>
Destination Weddings
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/fashion" data-filter-anchor="">
<input type="checkbox" class="hide" id="filter-input-67811" name="wedding-categories-checkbox-filters" value="fashion">
<label class="checkbox-label checkbox-label-left" for="filter-67811">
<span class="fake-checkbox icon icon-checkbox"></span>
Fashion
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/flower-arrangements" data-filter-anchor="">
<input type="checkbox" class="hide" id="filter-input-67812" name="wedding-categories-checkbox-filters" value="flower-arrangements">
<label class="checkbox-label checkbox-label-left" for="filter-67812">
<span class="fake-checkbox icon icon-checkbox"></span>
Flower Arrangements
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/food-catering" data-filter-anchor="">
<input type="checkbox" class="hide" id="filter-input-67813" name="wedding-categories-checkbox-filters" value="food-catering">
<label class="checkbox-label checkbox-label-left" for="filter-67813">
<span class="fake-checkbox icon icon-checkbox"></span>
Food + Catering
</label>
</a>
</li>
</ul>
</div>
</div>
<div class="panel">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#filters-accordion" href="#neckline-filters-radio" class="collapsed">
<h2 class="panel-title">
Neckline
<span class="content value" data-selected-filters="">Any</span>
</h2>
</a>
</div>
<div id="neckline-filters-radio" class="panel-collapse collapse filter-panel">
<ul class="xs-lg-divider list-unstyled panel-body" data-category="neckline-filters-radio" data-filter-category-container="">
<li data-display-id="none-radio">
<a href="/none" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-8632" name="neckline-filters-radio" value="none" data-no-selection="" checked="">
<label class="radio-label radio-label-left" for="filter-8632">
<span class="fake-radio icon icon-radio"></span>
None
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/bateau" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-0122" name="neckline-filters-radio" value="bateau">
<label class="radio-label radio-label-left" for="filter-0122">
<span class="fake-radio icon icon-radio"></span>
Bateau
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/halter" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-3452" name="neckline-filters-radio" value="halter">
<label class="radio-label radio-label-left" for="filter-3452">
<span class="fake-radio icon icon-radio"></span>
Halter
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/off-the-shoulder" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-6782" name="neckline-filters-radio" value="off-the-shoulder">
<label class="radio-label radio-label-left" for="filter-6782">
<span class="fake-radio icon icon-radio"></span>
Off-the-Shoulder
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/one-shoulder" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-67821" name="neckline-filters-radio" value="one-shoulder">
<label class="radio-label radio-label-left" for="filter-67821">
<span class="fake-radio icon icon-radio"></span>
One-Shoulder
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/scoop" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-67822" name="neckline-filters-radio" value="scoop">
<label class="radio-label radio-label-left" for="filter-67822">
<span class="fake-radio icon icon-radio"></span>
Scoop
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/square" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-67823" name="neckline-filters-radio" value="square">
<label class="radio-label radio-label-left" for="filter-67823">
<span class="fake-radio icon icon-radio"></span>
Square
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/strapless" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-67824" name="neckline-filters-radio" value="strapless">
<label class="radio-label radio-label-left" for="filter-67824">
<span class="fake-radio icon icon-radio"></span>
Strapless
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/sweetheart" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-67825" name="neckline-filters-radio" value="sweetheart">
<label class="radio-label radio-label-left" for="filter-67825">
<span class="fake-radio icon icon-radio"></span>
Sweetheart
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/v-neck" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-67826" name="neckline-filters-radio" value="v-neck">
<label class="radio-label radio-label-left" for="filter-67826">
<span class="fake-radio icon icon-radio"></span>
V-neck
</label>
</a>
</li>
<li data-display-id="1804">
<a href="/illusion" data-filter-anchor="">
<input type="radio" class="hide" id="filter-input-67827" name="neckline-filters-radio" value="illusion">
<label class="radio-label radio-label-left" for="filter-67827">
<span class="fake-radio icon icon-radio"></span>
Illusion
</label>
</a>
</li>
</ul>
</div>
</div>
<div class="panel">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#filters-accordion" href="#color-selection-filters" class="collapsed">
<h2 class="panel-title">
Color Selection filters
<span class="content value" data-selected-filters=""><span>(14)</span></span>
</h2>
</a>
</div>
<div id="color-selection-filters" class="panel-collapse collapse filter-panel">
<ul class="color-selection panel-body" data-category="color-selection-filters" data-filter-category-container="">
<li class="color-swatch white" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-white" value="filter-color-white" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-white"></label>
</li>
<li class="color-swatch ivory" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-ivory" value="filter-color-ivory" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-ivory"></label>
</li>
<li class="color-swatch gray" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-gray" value="filter-color-gray" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-gray"></label>
</li>
<li class="color-swatch silver" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-silver" value="filter-color-silver" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-silver"></label>
</li>
<li class="color-swatch black" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-black" value="filter-color-black" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-black"></label>
</li>
<li class="color-swatch brown" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-brown" value="filter-color-brown" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-brown"></label>
</li>
<li class="color-swatch yellow" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-yellow" value="filter-color-yellow" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-yellow"></label>
</li>
<li class="color-swatch gold" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-gold" value="filter-color-gold" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-gold"></label>
</li>
<li class="color-swatch orange" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-orange" value="filter-color-orange" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-orange"></label>
</li>
<li class="color-swatch red" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-red" value="filter-color-red" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-red"></label>
</li>
<li class="color-swatch pink" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-pink" value="filter-color-pink" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-pink"></label>
</li>
<li class="color-swatch purple" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-purple" value="filter-color-purple" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-purple"></label>
</li>
<li class="color-swatch blue" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-blue" value="filter-color-blue" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-blue"></label>
</li>
<li class="color-swatch green" data-display-id="1804">
<input type="checkbox" class="hide" id="swatch-green" value="filter-color-green" name="color-selection-filters" data-custom-filter="color" data-filter-anchor="">
<label class="checkbox" for="swatch-green"></label>
</li>
</ul>
</div>
</div>
</div>
<div class="filters-header">
<a class="content link text-center visible-xs-*" href="#" data-show-filters="">
Filter
<span class="icon icon-general-caret-down"></span>
</a>
<a class="content link text-center visible-xs-*" href="#" data-clear="">
<span class="clear-filters-text">Clear</span>
</a>
<a class="content link text-center hidden-md visible-xs-*" href="#" data-hide-filters="">
Hide Filters
<span class="icon icon-general-caret-up"></span>
</a>
</div>
</form>
</div>
</div>
Below is an example using a Ruby object of categories, filters and custom filter type and conditionally rendering single and multi selects, the radio filters will have a none option in addition to the other radio options in the filter:
<%
filters = [
{
name: "Train Length",
id: "135",
slug: "train-length-radio-filters",
is_radio: true,
terms: [
{ slug: "cathedral", name: "Cathedral", id: "123" },
{ slug: "chapel", name: "Chapel", id: "456" },
{ slug: "court", name: "Court", id: "789" },
{ slug: "semi-cathedral", name: "Semi-Cathedral", id: "7891011" },
{ slug: "sweep", name: "Sweep", id: "789101112" }
]
},
{
name: "Wedding Categories",
id: "246",
slug: "wedding-categories-checkbox-filters",
is_radio: false,
terms: [
{ slug: "bar-drinks", name: "Bar + Drinks", id: "012"},
{ slug: "beauty", name: "Beauty", id: "345"},
{ slug: "cakes-desserts", name: "Cakes + Desserts", id: "678"},
{ slug: "decorations-accents", name: "Decorations + Accents", id: "6789"},
{ slug: "destination-weddings", name: "Destination Weddings", id: "67810"},
{ slug: "fashion", name: "Fashion", id: "67811"},
{ slug: "flower-arrangements", name: "Flower Arrangements", id: "67812"},
{ slug: "food-catering", name: "Food + Catering", id: "67813"}
]
}, {
name: "Neckline",
id: "2462",
slug: "neckline-filters-radio",
is_radio: true,
terms: [
{ slug: "bateau", name: "Bateau", id: "0122"},
{ slug: "halter", name: "Halter", id: "3452"},
{ slug: "off-the-shoulder", name: "Off-the-Shoulder", id: "6782"},
{ slug: "one-shoulder", name: "One-Shoulder", id: "67821"},
{ slug: "scoop", name: "Scoop", id: "67822"},
{ slug: "square", name: "Square", id: "67823"},
{ slug: "strapless", name: "Strapless", id: "67824"},
{ slug: "sweetheart", name: "Sweetheart", id: "67825"},
{ slug: "v-neck", name: "V-neck", id: "67826"},
{ slug: "illusion", name: "Illusion", id: "67827"}
]
},
{
name: "Color Selection filters",
id: "357",
slug: "color-selection-filters",
is_radio: false,
custom_type: "color",
terms: [
{ slug:"filter-color-white", name:"white", id:"swatch-white" },
{ slug:"filter-color-ivory", name:"ivory", id:"swatch-ivory" },
{ slug:"filter-color-gray", name:"gray", id:"swatch-gray" },
{ slug:"filter-color-silver", name:"silver", id:"swatch-silver" },
{ slug:"filter-color-black", name:"black", id:"swatch-black" },
{ slug:"filter-color-brown", name:"brown", id:"swatch-brown" },
{ slug:"filter-color-yellow", name:"yellow", id:"swatch-yellow" },
{ slug:"filter-color-gold", name:"gold", id:"swatch-gold" },
{ slug:"filter-color-orange", name:"orange", id:"swatch-orange" },
{ slug:"filter-color-red", name:"red", id:"swatch-red" },
{ slug:"filter-color-pink", name:"pink", id:"swatch-pink" },
{ slug:"filter-color-purple", name:"purple", id:"swatch-purple" },
{ slug:"filter-color-blue", name:"blue", id:"swatch-blue" },
{ slug:"filter-color-green", name:"green", id:"swatch-green" }
]
}
]
random_number = rand(100..10000)
%>
<!-- Filters 2.0 -->
<div class="container container-flush">
<h1 id="filters-doc" style="margin-bottom:50px;">Filters v2.0</h1>
<div class="col-lg-4 col-md-4 col-sm-12 filters-form-container">
<form accept-charset="UTF-8" action="/marketplace/vendors" method="get" data-async data-filters-form>
<div data-filter-actions>
<p data-cta-filter-count>FILTERS</p>
<hr />
<div class="row-col-xs-6 row cta-button-row">
<div class="col-xs-6">
<a class="btn btn-primary btn-block" href="#" data-apply disabled>
<span class="filters-apply-text">Apply</span>
</a>
</div>
<div class="col-xs-6">
<a class="btn btn-alternate btn-block" href="#" data-clear disabled>
Clear
</a>
</div>
</div>
</div>
<div class="panel-group" id="filters-accordion" data-filters-accordion>
<% filters.each do |f| %>
<div class="panel">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#filters-accordion" href="#<%= f[:slug] %>" class="collapsed">
<h2 class="panel-title">
<%= f[:name] %>
<span class="content value" data-selected-filters></span>
</h2>
</a>
</div>
<div id="<%= f[:slug] %>" class="panel-collapse collapse filter-panel">
<% if f[:custom_type] && f[:custom_type] === "color" %>
<ul class="color-selection panel-body" data-category="<%= f[:slug] %>" data-filter-category-container>
<% f[:terms].each do |t| %>
<li class="color-swatch <%= t[:name] %>" data-display-id="1804">
<%= partial('_partials/_filters_2/filters_input',
:locals => { :category_slug => f[:slug],
:filter_slug => t[:slug],
:filter_id => t[:id],
:filter_name => t[:name],
:is_radio => f[:is_radio],
:type => f[:is_radio] ? "radio" : "checkbox",
:random_number => random_number,
:custom_template => 'color',
:custom_input_attr => ''
})
%>
</li>
<% end %>
</ul>
<% else %>
<ul class="xs-lg-divider list-unstyled panel-body" data-category="<%= f[:slug] %>" data-filter-category-container>
<% if f[:is_radio]%>
<li data-display-id="none-radio">
<%= partial('_partials/_filters_2/filters_input',
:locals => { :category_slug => f[:slug],
:filter_slug => 'none',
:filter_id => random_number,
:filter_name => 'Any',
:is_radio => f[:is_radio],
:type => f[:is_radio] ? "radio" : "checkbox",
:random_number => random_number,
:custom_template => false,
:custom_input_attr => 'data-no-selection'
#data-no-selection attribute shouldn't be changed, this is used in the js
# to determine that the 'none', 'all' or 'any' selection should not count
# as a selection.
})
%>
</li>
<% end %>
<% f[:terms].each do |t| %>
<li data-display-id="1804">
<%= partial('_partials/_filters_2/filters_input',
:locals => { :category_slug => f[:slug],
:filter_slug => t[:slug],
:filter_id => t[:id],
:filter_name => t[:name],
:is_radio => f[:is_radio],
:type => f[:is_radio] ? "radio" : "checkbox",
:random_number => random_number,
:custom_template => false,
:custom_input_attr => ''
})
%>
</li>
<% end %>
</ul>
<% end %>
</div>
</div>
<% end %>
</div>
<div class="filters-header">
<a class="content link text-center visible-xs-*" href="#" data-show-filters>
Filter
<span class="icon icon-general-caret-down"></span>
</a>
<a class="content link text-center visible-xs-*" href="#" data-clear>
<span class="clear-filters-text">Clear</span>
</a>
<a class="content link text-center hidden-md visible-xs-*" href="#" data-hide-filters>
Hide Filters
<span class="icon icon-general-caret-up"></span>
</a>
</div>
</form>
</div>
</div>
Filters input (filters_input) partial below:
<% if custom_template === false %>
<a href="/<%= filter_slug %>" data-filter-anchor>
<input type="<%= type %>"
class="hide" id="filter-input-<%= filter_id %>" name="<%= category_slug %>"
value="<%= filter_slug %>"
<%=custom_input_attr%>
<%=filter_slug === 'none' ? 'checked' : ''%>
/>
<label class="<%= type %>-label <%= type %>-label-left" for="filter-<%= filter_id %>">
<span class="fake-<%= type %> icon icon-<%= type %>"></span>
<%= filter_name %>
</label>
</a>
<% end %>
<% if custom_template === 'color' %>
<input type="checkbox" class="hide" id="<%= filter_id %>" value="<%= filter_slug %>" name="<%= category_slug %>" data-custom-filter="color" data-filter-anchor>
<label class="checkbox" for="<%= filter_id %>"></label>
<% end %>
Note:
The color filter inputs are not wrapped in an <a>
tag and have the data-custom-filter="color"
and data-filter-anchor
attributes on the input.
The javascript window object now has TKPL.Filters
object which makes selectedFilters available via
TKPL.Filters.selectedFilters
Filters exposes a "apply-filters" event when "Apply" button is clicked:
// $("[data-filters-form]").on('apply-filters', function (){
// console.log('Apply filters event triggered');
// });
Filters exposes a "clear-filters" event when "Clear" button is clicked:
// $("[data-filters-form]").on('clear-filters', function (){
// console.log('Clear filters event triggered');
// });