Fix bugs with select dropdown and multiselection
This commit is contained in:
parent
ed517c5ab7
commit
c81b261374
2 changed files with 21 additions and 16 deletions
|
@ -231,6 +231,13 @@ class GitLabDropdown
|
|||
html = @options.renderRow(data)
|
||||
else
|
||||
selected = if @options.isSelected then @options.isSelected(data) else false
|
||||
if not selected
|
||||
value = if @options.id then @options.id(data) else data.id
|
||||
fieldName = @options.fieldName
|
||||
field = @dropdown.parent().find("input[name='#{fieldName}'][value='#{value}']")
|
||||
if field.length
|
||||
selected = true
|
||||
|
||||
url = if @options.url then @options.url(data) else "#"
|
||||
text = if @options.text then @options.text(data) else ""
|
||||
cssClass = "";
|
||||
|
@ -263,7 +270,7 @@ class GitLabDropdown
|
|||
|
||||
rowClicked: (el) ->
|
||||
fieldName = @options.fieldName
|
||||
field = @dropdown.parent().find("input[name='#{fieldName}']")
|
||||
field = @dropdown.parent().find("input[name='#{fieldName}']")
|
||||
selectedIndex = el.parent().index()
|
||||
if @renderedData
|
||||
selectedObject = @renderedData[selectedIndex]
|
||||
|
@ -271,10 +278,11 @@ class GitLabDropdown
|
|||
field = @dropdown.parent().find("input[name='#{fieldName}'][value='#{value}']")
|
||||
|
||||
if el.hasClass(ACTIVE_CLASS)
|
||||
if @options.multiSelect
|
||||
console.log field.val(), value
|
||||
else
|
||||
field.remove()
|
||||
console.log 'has ACTIVE_CLASS'
|
||||
# if @options.multiSelect
|
||||
# console.log field.val(), value
|
||||
# else
|
||||
field.remove()
|
||||
else
|
||||
fieldName = @options.fieldName
|
||||
selectedIndex = el.parent().index()
|
||||
|
@ -286,11 +294,7 @@ class GitLabDropdown
|
|||
if !value?
|
||||
field.remove()
|
||||
|
||||
if @options.multiSelect
|
||||
oldValue = field.val()
|
||||
if oldValue
|
||||
value = "#{oldValue},#{value}"
|
||||
else
|
||||
if not @options.multiSelect
|
||||
@dropdown.find(".#{ACTIVE_CLASS}").removeClass ACTIVE_CLASS
|
||||
|
||||
# Toggle active class for the tick mark
|
||||
|
@ -299,14 +303,13 @@ class GitLabDropdown
|
|||
# Toggle the dropdown label
|
||||
if @options.toggleLabel
|
||||
$(@el).find(".dropdown-toggle-text").text @options.toggleLabel(selectedObject)
|
||||
|
||||
if value?
|
||||
if !field.length
|
||||
# Create hidden input for form
|
||||
input = "<input type='hidden' name='#{fieldName}' />"
|
||||
input = "<input type='hidden' name='#{fieldName}' value='#{value}' />"
|
||||
@dropdown.before input
|
||||
|
||||
@dropdown.parent().find("input[name='#{fieldName}']").val value
|
||||
else
|
||||
console.log 'has field???'
|
||||
|
||||
selectFirstRow: ->
|
||||
selector = '.dropdown-content li:first-child a'
|
||||
|
|
|
@ -65,7 +65,8 @@
|
|||
.light None
|
||||
|
||||
.selectbox.hide-collapsed
|
||||
= dropdown_tag("Milestone", options: { title: "Assign milestone", toggle_class: 'js-milestone-select', filter: true, dropdown_class: "dropdown-menu-selectable", placeholder: "Search milestones", data: { show_no: true, field_name: "milestone_id", project_id: @project.id, issuable_id: issuable.id, milestones: namespace_project_milestones_path(@project.namespace, @project, :json), issue_update: namespace_project_issue_path(@project.namespace, @project, issuable.id, :json), use_id: true }})
|
||||
= f.hidden_field 'milestone_id', value: issuable.milestone.id, id: nil
|
||||
= dropdown_tag("Milestone", options: { title: "Assign milestone", toggle_class: 'js-milestone-select', filter: true, dropdown_class: "dropdown-menu-selectable", placeholder: "Search milestones", data: { show_no: true, field_name: "issue[milestone_id]", project_id: @project.id, issuable_id: issuable.id, milestones: namespace_project_milestones_path(@project.namespace, @project, :json), issue_update: namespace_project_issue_path(@project.namespace, @project, issuable.id, :json), use_id: true }})
|
||||
|
||||
- if issuable.project.labels.any?
|
||||
.block.labels
|
||||
|
@ -85,7 +86,8 @@
|
|||
- else
|
||||
.light None
|
||||
.selectbox.hide-collapsed
|
||||
= f.hidden_field 'label_name', value: issuable.labels.map(&:id).join(',')
|
||||
- issuable.labels.each do |label|
|
||||
= f.hidden_field 'label_name', value: label.id, id: nil
|
||||
.dropdown
|
||||
%button.dropdown-menu-toggle.js-label-select.js-multiselect{type: "button", data: {toggle: "dropdown", field_name: "issue[label_name]", show_no: "true", show_any: "true", selected: issuable.label_names.join(","), project_id: (@project.id if @project), issue_update: namespace_project_issue_path(@project.namespace, @project, issuable.id, :json), labels: (namespace_project_labels_path(@project.namespace, @project, :json) if @project)}}
|
||||
%span.dropdown-toggle-text
|
||||
|
|
Loading…
Reference in a new issue