Sha256: adab0d01b919e1f4dfd4b9576938e20add9858bfa6e798e0e861cb049f7275c8

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module ActionView
  module Helpers
    module FormHelper
      def autosuggest_field(object_name, method, source, options={})
        text_field_class = "autosuggest_#{object_name}_#{method}"
        options[:class] = "#{options[:class].to_s} #{text_field_class}"
        autosuggest_options = options.delete(:autosuggest_options) || {}
        autosuggest_options.reverse_merge!("selectedItemProp" => "name", "searchObjProps" => "name", "neverSubmit" => "true", "asHtmlName" => "#{object_name}[set_#{method}]")

        _out = text_field(object_name, method, options)
        _out << raw(%{
          <script type="text/javascript">
            $(document).ready(function(){
              $('.#{text_field_class}').autoSuggest('#{source}', #{autosuggest_options.to_json});
            });
          </script>
        })
        _out
      end
    end

    module FormTagHelper
      def autosuggest_field_tag(name, value, source, options={})
        raise "todo"
      end
    end
  end
end

class ActionView::Helpers::FormBuilder #:nodoc:
  def autosuggest_field(method, source, options = {})
    @template.autosuggest_field(@object_name, method, source, objectify_options(options))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
autosuggest-rb-0.0.2 lib/autosuggest/form_helper.rb