は、ここで私はjQueryを使ってそれをやった方法は次のとおりです。
がヘルパーとしてこれを追加します。
module ActionView
module Helpers
module FormHelper
def autocomplete_text_area(object_name, method, source, options ={})
options["data-autocomplete"] = source
text_area(object_name, method, rewrite_autocomplete_option(options))
end
end
end
class ActionView::Helpers::FormBuilder
def autocomplete_text_area(method, source, options = {})
@template.autocomplete_text_area(@object_name, method, source, objectify_options(options))
end
end
end
これは、あなたがRailsの中にフォームヘルパーを延長する方法です。私たちがここでやっていることは、私たちが見ることができる独自のメソッドを追加することです。
今、あなたのjavascriptファイルの1つにこれを追加します。
$('textarea[data-autocomplete]').railsAutocomplete()
これが耳を傾け、私たちのテキストエリアに対応するためのオートコンプリートjsのスクリプトを設定します。
そして、あなたは今、あなたのビューでこのような何かを行うことができるはず:
f.autocomplete_text_area :name, autocomplete_menu_item_name_menus_path, placeholder: "Menu Item Name", class: 'input-lg menu_item', size: "45x2"
あなたが入力中に入力全体または個々の単語を自動的に完了したいですか? –
あなたが何を意味するのかわからない場合は、**入力タイプ=テキスト**ではなく、テキストエリアでオートコンプリートを使用したいと考えています – user984621
テキスト全体の値を選択するか、選択しますかテキスト内に入力された単語の値。 –