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

** Added optional clear button for filter feature (#374) ** #391

Merged
merged 3 commits into from
Oct 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion css/bootstrap-multiselect.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions js/bootstrap-multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
filterPlaceholder: 'Search',
// possible options: 'text', 'value', 'both'
filterBehavior: 'text',
includeFilterClearBtn: false,
preventInputChangeEvent: false,
nonSelectedText: 'None selected',
nSelectedText: 'selected',
Expand All @@ -254,6 +255,7 @@
button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"></button>',
ul: '<ul class="multiselect-container dropdown-menu"></ul>',
filter: '<li class="multiselect-item filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
filterClearBtn: '<span class="input-group-btn"><button class="btn btn-default multiselect-clear-filter" type="button"><i class="glyphicon glyphicon-remove-circle"></i></button></span>',
li: '<li><a href="javascript:void(0);"><label></label></a></li>',
divider: '<li class="multiselect-item divider"></li>',
liGroup: '<li class="multiselect-item group"><label class="multiselect-group"></label></li>'
Expand Down Expand Up @@ -673,6 +675,19 @@

this.$filter = $(this.options.templates.filter);
$('input', this.$filter).attr('placeholder', this.options.filterPlaceholder);

// Adds optional filter clear button
if(this.options.includeFilterClearBtn){
var clearBtn = $(this.options.templates.filterClearBtn);
clearBtn.on('click', $.proxy(function(event){
clearTimeout(this.searchTimeout);
this.$filter.find('.multiselect-search').val('');
$('li', this.$ul).show().removeClass("filter-hidden");
this.updateSelectAll();
}, this));
this.$filter.find('.input-group').append(clearBtn);
}

this.$ul.prepend(this.$filter);

this.$filter.val(this.query).on('click', function(event) {
Expand Down
8 changes: 8 additions & 0 deletions less/bootstrap-multiselect.less
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
}
}

.filter .btn {
padding: 6px 3px;
}

.filter .btn:hover {
color: red;
}

.btn-group > .btn-group:nth-child(2) > .multiselect.btn {
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
Expand Down