Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5983 (reopened defect)

Opened 2 years ago

Last modified 7 months ago

[PATCH] text_field_with_auto_complete ignores the :index property

Reported by: anonymous Assigned to: intersol
Priority: high Milestone: 1.2.7
Component: ActionPack Version: 1.1.6
Severity: normal Keywords: test patch
Cc: tarmo

Description

text_field has support for :index however the auto_complete tags do not.

Example: text_field_with_auto_complete :lineitem, :name, {:index => 0}

Generates: <input autocomplete="off" id="lineitem_0_name" name="lineitem[0][name]" size="30" type="text" /> <div class="auto_complete" id="lineitem_name_auto_complete"></div> <script type="text/javascript"> //<![CDATA[ var lineitem_0_name_auto_completer = new Ajax.Autocompleter('lineitem_0_name', 'lineitem_0_name_auto_complete', '/transaction/auto_complete_for_product_name', {}) //]]> </script>

As you can see, the div's don't match

Attachments

add_index_support_to_text_field_with_auto_complete.diff (2.7 kB) - added by ibroadfo on 11/09/06 18:15:46.
test-driven patch, implemented as per comment 2

Change History

08/31/06 02:15:14 changed by anonymous

A possible fix:

      def text_field_with_auto_complete(object, method, tag_options = {}, completion_options = {})
	if(tag_options[:index])
	    tag_name = "#{object}_#{tag_options[:index]}_#{method}"
	else
	    tag_name = "#{object}_#{method}"
	end
        (completion_options[:skip_style] ? "" : auto_complete_stylesheet) +
        text_field(object, method, tag_options) +
        content_tag("div", "", :id => tag_name + "_auto_complete", :class => "auto_complete") +
        auto_complete_field(tag_name, { :url => { :action => "auto_complete_for_" + tag_name } }.update(completion_options))
      end

08/31/06 15:46:56 changed by anonymous

slightly better solution:

      def text_field_with_auto_complete(object, method, tag_options = {}, completion_options = {})
	if(tag_options[:index])
	    tag_name = "#{object}_#{tag_options[:index]}_#{method}"
	else
	    tag_name = "#{object}_#{method}"
	end

	(completion_options[:skip_style] ? "" : auto_complete_stylesheet) +
        text_field(object, method, tag_options) +
        content_tag("div", "", :id => tag_name + "_auto_complete", :class => "auto_complete") +
        auto_complete_field(tag_name, { :url => { :action => "auto_complete_for_#{object}_#{method}" } }.update(completion_options))
      end

Here the auto_complete_for stays the same regardless of index.

11/06/06 21:59:48 changed by intersol

  • owner changed from David to intersol.
  • status changed from new to assigned.
  • milestone set to 1.2.

this solution should be included in edge.

11/06/06 22:12:42 changed by bitsweat

  • status changed from assigned to closed.
  • resolution set to untested.

11/09/06 18:15:46 changed by ibroadfo

  • attachment add_index_support_to_text_field_with_auto_complete.diff added.

test-driven patch, implemented as per comment 2

11/09/06 18:21:51 changed by ibroadfo

  • status changed from closed to reopened.
  • resolution deleted.

05/27/07 05:59:17 changed by danger

  • keywords set to test patch.

06/25/07 21:46:21 changed by matt

  • summary changed from text_field_with_auto_complete ignores the :index property to [PATCH] text_field_with_auto_complete ignores the :index property.

prefix the summary with [PATCH] so TRAC can manage this ticket properly.

08/07/07 06:19:49 changed by tarmo

  • cc set to tarmo.

Applies cleanly, tests pass, looks good. +1

12/15/07 21:21:48 changed by carpeliam

how is this coming? it'd be nice to see this code merged into the plugin.