Created
April 21, 2015 15:42
-
-
Save onozaty/a684d5e8087f03bc20c6 to your computer and use it in GitHub Desktop.
Better checkbox field by Redmine view customize plugin
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
// 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