-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from pulibrary/bootstrap_select_dropdown
Convert selects to bootstrap-select.
- Loading branch information
Showing
9 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
$(function (){ | ||
// for some strange reason selectpicker prevents the click-event. so just use mouseup | ||
// when clicking on an optgroup "label", toggle it's "children" | ||
$(document).on("mouseup", ".bootstrap-select .dropdown-header", function (){ | ||
var $optgroup = $(this), | ||
$ul = $optgroup.closest("ul"), | ||
optgroup = $optgroup.data("optgroup"), | ||
|
||
// options that belong to this optgroup | ||
$options = $ul.find("[data-optgroup="+optgroup+"]").not(".selected").not($optgroup); | ||
|
||
// show/hide options | ||
if($optgroup.hasClass("closed")) { | ||
$options.show(); | ||
} else { | ||
$options.hide(); | ||
} | ||
|
||
$optgroup.toggleClass("closed"); | ||
}); | ||
|
||
// initially close all optgroups that have the class "closed" | ||
$(document).on("loaded.bs.select", function (){ | ||
$(this).find(".dropdown-header.closed").each(function (){ | ||
var $optgroup = $(this), | ||
$ul = $optgroup.closest("ul"), | ||
optgroup = $optgroup.data("optgroup"), | ||
|
||
// options that belong to this optgroup | ||
$options = $ul.find("[data-optgroup="+optgroup+"]").not(".selected").not($optgroup); | ||
|
||
// show/hide options | ||
$options.hide(); | ||
}); | ||
}); | ||
$(document).on("changed.bs.select", function(){ | ||
$(this).find(".dropdown-header.closed").each(function(){ | ||
var $optgroup = $(this), | ||
$ul = $optgroup.closest("ul"), | ||
optgroup = $optgroup.data("optgroup"), | ||
|
||
// options that belong to this optgroup | ||
$options = $ul.find("[data-optgroup="+optgroup+"]").not(".selected").not($optgroup); | ||
|
||
// show/hide options | ||
if($optgroup.hasClass("closed")) { | ||
$options.hide(); | ||
} else { | ||
$options.show(); | ||
} | ||
}) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/views/records/edit_fields/_member_of_collection_ids.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<%= f.input :member_of_collection_ids, collection: @collections, label_method: :title, value_method: :id, input_html: { multiple: f.object.multiple?(key) }, include_blank: true, required: f.object.required?(key) %> | ||
<%= f.input :member_of_collection_ids, collection: @collections, label_method: :title, value_method: :id, input_html: { multiple: f.object.multiple?(key) }, include_blank: false, required: f.object.required?(key) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters