diff --git a/app/assets/javascripts/crop_suggest.js.coffee b/app/assets/javascripts/crop_suggest.js.coffee new file mode 100644 index 000000000..93802fc7c --- /dev/null +++ b/app/assets/javascripts/crop_suggest.js.coffee @@ -0,0 +1,21 @@ +jQuery -> + if el = $( '.crop-suggest' ) + el.autocomplete + minLength: 1, + source: Routes.crops_search_path(), + focus: ( event, ui ) -> + el.val( ui.item.name ) + $( "[id$='_crop_id']" ).val( ui.item.id ) + false + select: ( event, ui ) -> + el.val( ui.item.name ) + $( "[id$='_crop_id']" ).val( ui.item.id ) + false + autoFocus: true + if el.data( 'uiAutocomplete' ) + el.data( 'uiAutocomplete' )._renderItem = ( ul, item ) -> + $( '
  • ' ) + .data( 'item.autocomplete', item ) + .append( "#{item.name}" ) + .appendTo( ul ) + diff --git a/app/assets/javascripts/plantings.js.coffee b/app/assets/javascripts/plantings.js.coffee index 0bbf50e8d..ab5b73462 100644 --- a/app/assets/javascripts/plantings.js.coffee +++ b/app/assets/javascripts/plantings.js.coffee @@ -4,25 +4,3 @@ jQuery -> $('.add-datepicker').datepicker('format' : 'yyyy-mm-dd') - -jQuery -> - if el = $( '#crop' ) - el.autocomplete - minLength: 1, - source: Routes.crops_search_path(), - focus: ( event, ui ) -> - el.val( ui.item.name ) - $( '#planting_crop_id' ).val( ui.item.id ) - false - select: ( event, ui ) -> - el.val( ui.item.name ) - $( '#planting_crop_id' ).val( ui.item.id ) - false - autoFocus: true - if el.data( 'uiAutocomplete' ) - el.data( 'uiAutocomplete' )._renderItem = ( ul, item ) -> - $( '
  • ' ) - .data( 'item.autocomplete', item ) - .append( "#{item.name}" ) - .appendTo( ul ) - diff --git a/app/views/harvests/_form.html.haml b/app/views/harvests/_form.html.haml index 181d0af54..097d27caf 100644 --- a/app/views/harvests/_form.html.haml +++ b/app/views/harvests/_form.html.haml @@ -9,7 +9,8 @@ .control-group = f.label 'What did you harvest?', :class => 'control-label' .controls - = collection_select(:harvest, :crop_id, Crop.all, :id, :name, :selected => @harvest.crop_id || @crop.id) + = text_field_tag(:crop, @harvest.crop.nil? ? "" : @harvest.crop.name, :class => 'crop-suggest') + = f.hidden_field(:crop_id) = collection_select(:harvest, :plant_part_id, PlantPart.all, :id, :name, :selected => @harvest.plant_part_id) %span.help-block Can't find what you're looking for? diff --git a/app/views/plantings/_form.html.haml b/app/views/plantings/_form.html.haml index 5da8bff30..b7f58b2c7 100644 --- a/app/views/plantings/_form.html.haml +++ b/app/views/plantings/_form.html.haml @@ -9,7 +9,7 @@ .control-group = f.label :crop, 'What did you plant?', :class => 'control-label' .controls - = text_field_tag(:crop, @planting.crop.nil? ? "" : @planting.crop.name) + = text_field_tag(:crop, @planting.crop.nil? ? "" : @planting.crop.name, :class => 'crop-suggest') = f.hidden_field(:crop_id) %span.help-inline Can't find what you're looking for?