Commit f3afcb87 authored by Phil Hughes's avatar Phil Hughes

Correctly handles multi-selected values

Fixes an issue where values couldnlt be unselected
parent 6c891962
...@@ -39,7 +39,7 @@ class GitLabDropdownFilter ...@@ -39,7 +39,7 @@ class GitLabDropdownFilter
key: @options.keys key: @options.keys
) )
@callback results @options.callback results
class GitLabDropdownRemote class GitLabDropdownRemote
constructor: (@dataEndpoint, @options) -> constructor: (@dataEndpoint, @options) ->
...@@ -75,6 +75,7 @@ class GitLabDropdownRemote ...@@ -75,6 +75,7 @@ class GitLabDropdownRemote
class GitLabDropdown class GitLabDropdown
LOADING_CLASS = "is-loading" LOADING_CLASS = "is-loading"
PAGE_TWO_CLASS = "is-page-two" PAGE_TWO_CLASS = "is-page-two"
ACTIVE_CLASS = "is-active"
constructor: (@el, @options) -> constructor: (@el, @options) ->
self = @ self = @
...@@ -225,6 +226,12 @@ class GitLabDropdown ...@@ -225,6 +226,12 @@ class GitLabDropdown
html += "</li>" html += "</li>"
rowClicked: (el) -> rowClicked: (el) ->
fieldName = @options.fieldName
field = @dropdown.parent().find("input[name='#{fieldName}']")
if el.hasClass(ACTIVE_CLASS)
field.remove()
else
fieldName = @options.fieldName fieldName = @options.fieldName
selectedIndex = el.parent().index() selectedIndex = el.parent().index()
if @renderedData if @renderedData
...@@ -232,19 +239,24 @@ class GitLabDropdown ...@@ -232,19 +239,24 @@ class GitLabDropdown
value = if @options.id then @options.id(selectedObject, el) else selectedObject.id value = if @options.id then @options.id(selectedObject, el) else selectedObject.id
if @options.multiSelect if @options.multiSelect
fieldName = "#{fieldName}[]" oldValue = field.val()
if oldValue
value = "#{oldValue},#{value}"
else else
@dropdown.find('.is-active').removeClass 'is-active' @dropdown.find(ACTIVE_CLASS).removeClass ACTIVE_CLASS
@dropdown.parent().find("input[name='#{fieldName}']").remove() field.remove()
# Toggle active class for the tick mark # Toggle active class for the tick mark
el.toggleClass "is-active" el.toggleClass "is-active"
if value if value
if !field.length
# Create hidden input for form # Create hidden input for form
input = "<input type='hidden' name='#{fieldName}' value='#{value}' />" input = "<input type='hidden' name='#{fieldName}' />"
@dropdown.before input @dropdown.before input
@dropdown.parent().find("input[name='#{fieldName}']").val value
selectFirstRow: -> selectFirstRow: ->
selector = '.dropdown-content li:first-child a' selector = '.dropdown-content li:first-child a'
if @dropdown.find(".dropdown-toggle-page").length if @dropdown.find(".dropdown-toggle-page").length
......
...@@ -4,6 +4,8 @@ class @LabelsSelect ...@@ -4,6 +4,8 @@ class @LabelsSelect
projectId = $(dropdown).data('project-id') projectId = $(dropdown).data('project-id')
labelUrl = $(dropdown).data("labels") labelUrl = $(dropdown).data("labels")
selectedLabel = $(dropdown).data('selected') selectedLabel = $(dropdown).data('selected')
if selectedLabel
selectedLabel = selectedLabel.split(",")
newLabelField = $('#new_label_name') newLabelField = $('#new_label_name')
newColorField = $('#new_label_color') newColorField = $('#new_label_color')
showNo = $(dropdown).data('show-no') showNo = $(dropdown).data('show-no')
...@@ -63,6 +65,13 @@ class @LabelsSelect ...@@ -63,6 +65,13 @@ class @LabelsSelect
callback data callback data
renderRow: (label) -> renderRow: (label) ->
if $.isArray(selectedLabel)
selected = ""
$.each selectedLabel, (i, selectedLbl) ->
selectedLbl = selectedLbl.trim()
if selected is "" && label.title is selectedLbl
selected = "is-active"
else
selected = if label.title is selectedLabel then "is-active" else "" selected = if label.title is selectedLabel then "is-active" else ""
"<li> "<li>
......
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