class SearchStopAreaInput < Formtastic::Inputs::SearchInput def search if options[:json] tokenLimit = options[:tokenLimit].present? ? options[:tokenLimit] : "null" template.content_tag( :script, ("$(document).ready(function() { var item_name = function( item){ var result = item.short_name; if ( item.short_registration_number != '' ) { result += ' [' + item.short_registration_number + ']'; } return result; }; var item_localization = function( item){ var localization = item.zip_code + ' ' + item.short_city_name; return localization; }; var item_format = function( item ){ var name = item_name( item ); var localization = item_localization( item ); html_result = '
  • '; html_result += '' if(name != '') { html_result += '' + name + '' ; } if(localization != '') { html_result += '' + localization + ''; } html_result += '
  • '; return html_result; }; $('##{dom_id}').tokenInput('#{options[:json]}', { zindex: 1061, disabled: #{options[:disabled] || false}, crossDomain: false, tokenLimit: #{tokenLimit}, minChars: 2, preventDuplicates: true, hintText: '#{options[:hint_text]}', noResultsText: '#{options[:no_result_text]}', searchingText: '#{options[:searching_text]}', resultsFormatter: item_format, tokenFormatter: item_format, }); });").html_safe) end end def to_html input_wrapping do label_html << builder.search_field(method, input_html_options) << search end end def input_html_options css_class = super[:class] super.merge({ :required => nil, :autofocus => nil, :class => "#{css_class} token-input", 'data-model-name' => object.class.model_name.human }) end end