make crop_suggest.js more abstract so it works for other resources, not just planting

This commit is contained in:
Taylor Griffin committed 2014-08-01 19:19:27 +10:00
1 parent b4fdf97056
commit a49880d4da
4 files changed
+24 -24

No files matched your search

@@ -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 ) ->
$( '<li></li>' )
.data( 'item.autocomplete', item )
.append( "<a>#{item.name}</a>" )
.appendTo( ul )
@@ -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 ) ->
$( '<li></li>' )
.data( 'item.autocomplete', item )
.append( "<a>#{item.name}</a>" )
.appendTo( ul )
+2 -1
View File
@@ -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?
+1 -1
View File
@@ -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?