Commit 85d5f606f656fc8680e28baf3d58d24898d23261
1 parent
2b921a6c
Exists in
master
and in
4 other branches
Labels autocomplete
Showing
3 changed files
with
45 additions
and
0 deletions
Show diff stats
app/assets/javascripts/main.js.coffee
| ... | ... | @@ -13,6 +13,12 @@ window.errorMessage = (message) -> |
| 13 | 13 | ehtml.html(message) |
| 14 | 14 | ehtml |
| 15 | 15 | |
| 16 | +window.split = (val) -> | |
| 17 | + return val.split( /,\s*/ ) | |
| 18 | + | |
| 19 | +window.extractLast = (term) -> | |
| 20 | + return split( term ).pop() | |
| 21 | + | |
| 16 | 22 | # Disable button if text field is empty |
| 17 | 23 | window.disableButtonIfEmptyField = (field_selector, button_selector) -> |
| 18 | 24 | field = $(field_selector) | ... | ... |
app/helpers/issues_helper.rb
app/views/issues/_form.html.haml
| ... | ... | @@ -55,3 +55,36 @@ |
| 55 | 55 | = link_to "Cancel", project_issues_path(@project), class: cancel_class |
| 56 | 56 | - else |
| 57 | 57 | = link_to "Cancel", project_issue_path(@project, @issue), class: cancel_class |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | +:javascript | |
| 63 | + $(function(){ | |
| 64 | + $("#issue_label_list") | |
| 65 | + .bind( "keydown", function( event ) { | |
| 66 | + if ( event.keyCode === $.ui.keyCode.TAB && | |
| 67 | + $( this ).data( "autocomplete" ).menu.active ) { | |
| 68 | + event.preventDefault(); | |
| 69 | + } | |
| 70 | + }) | |
| 71 | + .autocomplete({ | |
| 72 | + minLength: 0, | |
| 73 | + source: function( request, response ) { | |
| 74 | + response( $.ui.autocomplete.filter( | |
| 75 | + #{raw labels_autocomplete_source}, extractLast( request.term ) ) ); | |
| 76 | + }, | |
| 77 | + focus: function() { | |
| 78 | + return false; | |
| 79 | + }, | |
| 80 | + select: function(event, ui) { | |
| 81 | + var terms = split( this.value ); | |
| 82 | + terms.pop(); | |
| 83 | + terms.push( ui.item.value ); | |
| 84 | + terms.push( "" ); | |
| 85 | + this.value = terms.join( ", " ); | |
| 86 | + return false; | |
| 87 | + } | |
| 88 | + }); | |
| 89 | + }); | |
| 90 | + | ... | ... |