Commit 4e486c61 authored by Alfredo Sumaran's avatar Alfredo Sumaran Committed by Jacob Schatz

Allow to pass input filter param

This allow us to set a different input to filter results
parent 0b893bec
...@@ -2,7 +2,9 @@ class GitLabDropdownFilter ...@@ -2,7 +2,9 @@ class GitLabDropdownFilter
BLUR_KEYCODES = [27, 40] BLUR_KEYCODES = [27, 40]
constructor: (@dropdown, @options) -> constructor: (@dropdown, @options) ->
@input = @dropdown.find(".dropdown-input .dropdown-input-field") {
@input
} = @options
# Key events # Key events
timeout = "" timeout = ""
...@@ -77,14 +79,30 @@ class GitLabDropdown ...@@ -77,14 +79,30 @@ class GitLabDropdown
PAGE_TWO_CLASS = "is-page-two" PAGE_TWO_CLASS = "is-page-two"
ACTIVE_CLASS = "is-active" ACTIVE_CLASS = "is-active"
FILTER_INPUT = '.dropdown-input .dropdown-input-field'
constructor: (@el, @options) -> constructor: (@el, @options) ->
self = @
@dropdown = $(@el).parent() @dropdown = $(@el).parent()
# Set Defaults
{
# If no input is passed create a default one
@filterInput = @$(FILTER_INPUT)
} = @options
self = @
# If selector was passed
if _.isString(@filterInput)
@filterInput = @$(@filterInput)
search_fields = if @options.search then @options.search.fields else []; search_fields = if @options.search then @options.search.fields else [];
if @options.data if @options.data
# If data is an array # If data is an array
if _.isArray @options.data if _.isArray @options.data
@fullData = @options.data
@parseData @options.data @parseData @options.data
else else
# Remote data # Remote data
...@@ -100,6 +118,7 @@ class GitLabDropdown ...@@ -100,6 +118,7 @@ class GitLabDropdown
# Init filiterable # Init filiterable
if @options.filterable if @options.filterable
@filter = new GitLabDropdownFilter @dropdown, @filter = new GitLabDropdownFilter @dropdown,
input: @filterInput
remote: @options.filterRemote remote: @options.filterRemote
query: @options.data query: @options.data
keys: @options.search.fields keys: @options.search.fields
...@@ -133,6 +152,9 @@ class GitLabDropdown ...@@ -133,6 +152,9 @@ class GitLabDropdown
if self.options.clicked if self.options.clicked
self.options.clicked() self.options.clicked()
$: (selector) ->
$(selector, @dropdown)
toggleLoading: -> toggleLoading: ->
$('.dropdown-menu', @dropdown).toggleClass LOADING_CLASS $('.dropdown-menu', @dropdown).toggleClass LOADING_CLASS
...@@ -167,7 +189,7 @@ class GitLabDropdown ...@@ -167,7 +189,7 @@ class GitLabDropdown
@remote.execute() @remote.execute()
if @options.filterable if @options.filterable
@dropdown.find(".dropdown-input-field").focus() @filterInput.focus()
hidden: => hidden: =>
if @options.filterable if @options.filterable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment