Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Better checkbox field by Redmine view customize plugin
// Path pattern: /issues/
// Type : JavaScript
$(function() {
$('.check_box_group')
.each(function() {
var checkBoxGroup = $(this);
checkBoxGroup.hide();
var checkedValueLine =
$('<span>')
.insertBefore(checkBoxGroup)
.text(collectCheckedValues(checkBoxGroup));
$('<a href="#"><img alt="Edit" src="/images/edit.png" style="vertical-align: middle"></a>')
.insertAfter(checkedValueLine)
.on('click', function() {
$(this).hide();
checkBoxGroup.show();
return false;
});
$('<input type="text">')
.prependTo(checkBoxGroup)
.on('keyup', function() {
var inputText = $(this).val();
checkBoxGroup.find('label')
.each(function() {
var label = $(this);
if (match(inputText, label.find('input').val())) {
label.show();
} else {
label.hide();
}
});
});
checkBoxGroup.on('change', function() {
checkedValueLine.text(collectCheckedValues(checkBoxGroup));
});
});
function collectCheckedValues(target) {
return target.find(':checked')
.map(function() { return $(this).val(); })
.get().join(', ') || '\u00a0';
}
function match(inputText, targetValue) {
return inputText == ''
|| targetValue.toLowerCase().indexOf(inputText.toLowerCase()) != -1;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.