risuiowa / rails-jquery-autocomplete Goto Github PK
View Code? Open in Web Editor NEWAn easy and unobtrusive way to use jQuery's autocomplete with Rails 3 and later.
License: MIT License
An easy and unobtrusive way to use jQuery's autocomplete with Rails 3 and later.
License: MIT License
I am using rails form helper with one model's data on several controllers/views. Like let's say I have a comments model and use comments at many occasions.
In this particular case I am using several forms in an admin namespace. With normal select fields I have a working solution but I don't know how to access the correct data. As I don't have too much Rails experience right now I am stuck. That's why maybe someone here can help me out.
In my example I am using a form for a @gallery
on a foreign admins controller. In the form right now I let editors chose which @game
belongs to a @gallery
. Like so:
<%= form_for(@gallery) do |f| %>
...
<%= f.select :game_id, options_for_select(@games.map {|g| [g.name, g.id]}) %>
...
<% end %>
If I use <%= f.autocomplete_field :name, autocomplete_name_games_path %>
instead it tells me, that :name
is not available with my @gallery
object, which is true, but I thought I could use the autocomplete of the games controller at this place, too.
Kind regards
It is not clear how we can get a stylesheet for this jquery autocompletion.
I am using rails-sass, am I supposed to also grab jquery-ui-sass-rails
and add a require line for jquery.ui or something like that ?
Unfortunately I added jquery ui only for this purpose, it would be great if the readme could mention the steps to get some basic working css.
Actually the option scopes
is mentionned in the Readme
but it only works with ActiveRecord
. I would be useful to also have it on Mongoid
.
If interested, I can try to make a PR starting from crowdint/rails3-jquery-autocomplete#171
It looks like the autocomplete plugin can no longer initialise, and fails silently, because jQuery 3 removed the selector
property used on line 27 in the main plugin function.
Their advice on that page is to supply the selector as a parameter, e.g. jQuery(document).railsAutocomplete('input[data-autocomplete]')
.
The workaround is to copy the handler yourself:
jQuery(document).on("focus", "input[data-autocomplete]", function() {
if (!this.railsAutoCompleter) {
this.railsAutoCompleter = new jQuery.railsAutocomplete(this);
}
});
Unfortunately I think there are also other jQuery 3 issues such as the position of the selection list. Hopefully this saves someone some time debugging.
When checking for showNoMatches, you're currently doing a boolean check. However, if you get the value from the form element's 'data-showNoMatches' attribute, you will get a string. In javascript, the string "false" will evaluate to true.
You either need to special case the retrieval of boolean values from data-attributes and do some sort of string -> boolean conversion
if (value === 'false') {
value = false
}
Or, do a string check when testing the value
if (option && option !== 'false') {
// do some stuff here
}
I have 2 search boxes in a form where the first one returns the customer name and the second should return the all the customers' companies.
Everything seems to work okay except if 2 customers have the same company in the database, the company autocomplete field returns the same company twice.
I tried setting the scope in the controller like this:
autocomplete :customer, :name, full:true
autocomplete :customer, :company, full:true, scopes:[:compscope]
And here is the scope:
scope :compscope, -> {Customer.select("DISTINCT company")}
Here is the view (in slim)
.field
= f.label :company
br
= f.autocomplete_field :company, :autocomplete_customer_company
Could you help me fix it so the field returns unique results?
Assuming a json output of
[{
id: "2",
label: "tram",
value: "tram"
}]
How would I change it so that label = tram but value = 2, I need to post the ID of the object not the name.
Hello!
I'm working on a application that needs some scopes, like User.friends(current_user.id) for the autocomplete. I was able to do that by overriding the get_autocomplete_items. But the problem is that I have two autocomplete paths for the same controller which I overrided the method:
The autocomplete_user_name_users_path and the and the autocomplete_user_email_users_path.
And now they both get "filtered" the same way because of the overriding of the autocomplete method. Is there a way to put another param beside the "term" param that goes to the method? than I could just put an if and be happy.. Or if there is another solution for this.
Hi i'm new, this works well in development, but not in production. Help me please.
What should I replace 'brand' with in the line autocomplete :brand :name
when the class name is ActsAsTaggableOn::Tag?
I used the rails3-jquery-autocomplete gem with rails 3 application and arrows up and down was working fine, but when upgrading to rails 4 and using this gem, the arrows are no more working. Please provide us with solution if there are any conflicts with JS of the upgraded gem ?
The ajax request is well sent but the results are not rendered. But by typing 'tab' the first result is set as the input value (results exist, but are not displayed)
Thanks,
Clément
We already use this gem for a Rails 4.2.0 app. I wanted to implement it for this other app, Rails 4.1.1, but I am having issues. I ran bundle install
along with rails g ...
to store the javascript file in public/javascripts
. I have even restarted the app with no success.
gem 'rails', '4.1.1'
gem 'rails-jquery-autocomplete'
gem 'jquery-rails'
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require jquery-ui/autocomplete
//= require autocomplete-rails
//= require_tree .
//= require jquery_nested_form
//= require bootstrap
//= require turbolinks
Here is my error message:
Showing /home/hstevens/contract_app/app/views/layouts/application.html.haml where line #6 raised:
couldn't find file 'jquery-ui/autocomplete'
(in /home/hstevens/contract_app/app/assets/javascripts/application.js:16)
3 %head
4 %title Contract Application
5 = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
6 = javascript_include_tag 'application', 'data-turbolinks-track' => true
7 = javascript_include_tag 'autocomplete-rails.js'
8 = csrf_meta_tags
9 %body
Just a quick heads-up and suggestion for the readme:
Using :id_element => "#client_id"
with formtastic will not yield the expected result (will not work).
The id_element
has to be wrapped like this:
f.input :client_name, input_html: { data: { :id_element => "#client_id" } }, :as => :autocomplete,
url: autocomplete_client_name_clients_path
Took me a few minutes to figure out, might help someone with the same problem.
I use ruby 2.3.0 as default version. When I run rake test after bundle install.
Errors happen:
/Users/lingceng/.rvm/rubies/ruby-2.3.0/bin/ruby -I"lib:lib:test" -I"/Users/lingceng/.rvm/gems/ruby-2.3.0/gems/rake-10.5.0/lib" "/Users/lingceng/.rvm/gems/ruby-2.3.0/gems/rake-10.5.0/lib/rake/rake_test_loader.rb" "test/**/*_test.rb"
/Users/lingceng/.rvm/gems/ruby-2.3.0/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/assertion_error.rb:4:in `require': cannot load such file -- minitest/unit (LoadError)
from /Users/lingceng/.rvm/gems/ruby-2.3.0/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/assertion_error.rb:4:in `<module:Matchers>'
I change to ruby2.1.5, tests passed.
This is my Application.js
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require autocomplete-rails
//= require highcharts.js
//= require masonry.js
//= require moment
//= require bootstrap-datepicker
//= require bootstrap-datetimepicker
//= require chosen-jquery
//= require tinymce-jquery
//= require_tree .
my rails version 4.0.2. This happens only in production mode, in dev mode works well. Help me please, thanks.
I'm now using the head version.
This does fix the deprecated warnings from simple_form for me.
And it seems to work just fine for me.
I'd like to suggest that you release that new version as 1.1.0
(because this really is a big fix for all of us)
Thanks for the improvements.
I believe there is much more to come.
Looks like this is now the premiere gem for handling autocomplete.
I patched it way back to also deliver images links and such.
As a last note, you might even consider to do away with the dependecies on jquery.
Like making this the rails autocomplete gem.
~eike
Hi Folks,
can you help me out pls? This is probably not an issue with the code but with me being a beginner.
Got the autocomplete working but it only works when I am logged on (devise). When I am not logged on no suggestion pops under and when I inspect the element I see this in the Console tab I see:
Failed to load resource: the server responded with a status of 401 (Unauthorized)
https://xxxxxxxxxxxx.c9.io/assets/jquery.self-d03a5....f96ea7c074.js?body=1
and it points to this in the Sources tab
xhr.send( ( options.hasContent && options.data ) || null );
I googled this and found a few stackoverflow suggestions regarding this
<%= csrf_meta_tags %>
in my application.html.erb but I didn't understand most :) and the rest didn't help. :(
TIA!
Hi all!
I'm working on an app, that has a client model. The client has a first_name and last_name attributes and an attr_accessible full_name.
I'd like to be able to search through the database, using full name but I get an exception, that the column full_name does not exist.
Is there a workaround for this? I'd really want to avoid adding a name (or full_name) column.
Thanks for triggering the change event.
But this did not autosubmit the form for me.
It probably should not? But just trigger the change event?
Maybe I was doing something wrong.
Otherwise adding an configurable autosubmit facility might make a lot of sense for a lot of use cases.
I reverted back to the soution that I used with the old rails3-autocomplete.
I use this bit of coffee which makes this work for me
(need to give the input field the class 'autocomplete_submit', probably data-autosubmit would be even better ...)
#
# submit autocomplete on select
# drop this into assets/javascript/autocomplete_submit.coffee
#
$ ->
$('.autocomplete_submit')
.bind 'railsAutocomplete.select',
(event, data) ->
$(this).closest('form').submit()
I am using pg_search, and I have a search method defined as a pg_search_scope.
I thought I could simply do:
autocomplete :node, :search
Given that my search scope method name is search
and the model is Node
, but when I tried that I get this error:
PG::UndefinedColumn: ERROR: column nodes.search does not exist
LINE 1: SELECT nodes.id, nodes.search FROM "nodes" WHERE (LOWER(no...
How do I specify autocomplete on a method rather than a column name, if that is possible?
Edit 1
I tried doing:
autocomplete :node, :name, scopes: [:search]
Where this is my scope:
include PgSearch
pg_search_scope :search, against: [:name, :user_id, :circa, :cached_user_tag_list, :cached_tagged_user_names],
using: { tsearch: { any_word: true, dictionary: :english, prefix: true} },
:associated_against => {
comments: [:message],
user: [:first_name, :last_name, :email],
memberships: [:relation],
user_tags: [:name]
}
And this is the result I get:
ArgumentError - wrong number of arguments (0 for 1):
pg_search (0.7.9) lib/pg_search.rb:38:in `block in pg_search_scope'
activerecord (4.1.6) lib/active_record/relation/delegation.rb:94:in `block in method_missing'
activerecord (4.1.6) lib/active_record/relation.rb:292:in `scoping'
activerecord (4.1.6) lib/active_record/relation/delegation.rb:94:in `method_missing'
rails-jquery-autocomplete (1.0.0) lib/rails-jquery-autocomplete/orm/active_record.rb:24:in `block in active_record_get_autocomplete_items'
rails-jquery-autocomplete (1.0.0) lib/rails-jquery-autocomplete/orm/active_record.rb:24:in `active_record_get_autocomplete_items'
rails-jquery-autocomplete (1.0.0) lib/rails-jquery-autocomplete/autocomplete.rb:57:in `block in autocomplete'
rails-jquery-autocomplete (1.0.0) lib/rails-jquery-autocomplete/autocomplete.rb:69:in `block in autoc
@bigtunacan Any ideas for this?
Any way to adjust how many characters are required before it performs a search? minLength is defaulted to 1, but 2 characters are required to search when I implement the gem. I tried 'data-min-length' => 1
to try and force it, but to no avail. Thanks.
I am trying to use the autocomplete view helpers with rails cells.
It would be greate to package the view helpers in a module that could be included in cells. Right now you are adding methods to ActionView but it would be better to (also) distribute them via a Helper that we can choose to include or not.
Otherwise, if we use a different context than ActionView we won't be able to do anything because of undefined methods
turns out it is not possible
Using the multiple option seems to do nothing and have no effect on the output html. Is this an option that's supposed to be working?
I have two models, movements and products, one movement has many products. I want to use autocomplete for select products in nested-form.
I'd like to add another code snippet that I'm using with autocomplete.
This is more a recipe how to extend jquery-ui autocomplete rendering.
But other people might find this useful as well.
You might want to add this to the examples section.
This solution is quite ad hoc, but might be useful as a starting point.
We might even come up with a much better solution.
I'd imagine that the code for rendering the rows
should better be done with rails templates.
But in this example I do it with some crufty js/coffee
$ ->
jQuery.widget 'ui.autocomplete', jQuery.ui.autocomplete,
_renderItem: (ul, item) ->
a = $('<a>')
if(item.id > 0)
a.append $('<img class="autocomplete-icon">').attr('src', '/cover/48/'+item.id+'a.jpg')
a.append $('<div class="autocomplete-text">').text(item.label)
li = $("<li>").attr("data-value", item.value)
return li.append(a).appendTo(ul)
So what this does is that it looks up the id to display an icon in front of every row.
https://github.com/peterwillcn/rails4-autocomplete Moved to this project(https://github.com/bigtunacan/rails-jquery-autocomplete). :-)
Thanks for this great job first, guys !
I don't understand why the default search trigger input length is 2. Although it could be set on element, but really need hook to set the length for global application.
I want to use rails-jquery-autocomplete but my source is a dynamic array from a field in my model. The documentation only talks about the source being separate model instances. Is there a way to make it use an array and look at each array item as a separate object when querying the source?
"This will create an action autocomplete_brand_name on your controller, don't forget to add it on your routes file"
This never happens. I always get an exception that the action is not there.
hi, i'm a newer
here is the Gemfile
gem 'rails', '4.2.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'rails-jquery-autocomplete'
i think i had followed the step
autocomplete_brand_name_products_path
is okthat all.
am i missing something important?
thank you!
Hey guys,
I'm using this plugin for http://syntaxcenter.com, and for one instance the plugin works great. Unfortunately if I try it on another computer or browser (instance), the server returns 401 on the GET request. Any ideas as to why this is happening?
After installing and configuring this gem, I get this issue. Has anyone else experienced this before? Removal of the gem fixes the issue.
If you would like to see the source for the project I'm working on to make sure it's something from this gem:
https://github.com/ilovemysillybanana/pastie
remote: -----> Preparing app for Rails asset pipeline remote: Running: rake assets:precompile remote: rake aborted! remote: ExecJS::ProgramError: Unexpected token punc «{», expected punc «,» (line: 17449, col: 75, pos: 529891) remote: Error remote: at new JS_Parse_Error (/tmp/execjs20160414-361-1vm04s1js:2659:11936) remote: at js_error (/tmp/execjs20160414-361-1vm04s1js:2659:12155) remote: at croak (/tmp/execjs20160414-361-1vm04s1js:2659:20622) remote: at token_error (/tmp/execjs20160414-361-1vm04s1js:2659:20759) remote: at expect_token (/tmp/execjs20160414-361-1vm04s1js:2659:20982) remote: at expect (/tmp/execjs20160414-361-1vm04s1js:2659:21120) remote: at ctor.argnames (/tmp/execjs20160414-361-1vm04s1js:2659:25664) remote: at function_ (/tmp/execjs20160414-361-1vm04s1js:2659:25728) remote: at expr_atom (/tmp/execjs20160414-361-1vm04s1js:2659:28965) remote: at maybe_unary (/tmp/execjs20160414-361-1vm04s1js:2659:31652) remote: at expr_ops (/tmp/execjs20160414-361-1vm04s1js:2660:404) remote: at maybe_conditional (/tmp/execjs20160414-361-1vm04s1js:2660:496) remote: at maybe_assign (/tmp/execjs20160414-361-1vm04s1js:2660:939)new JS_Parse_Error ((execjs):2659:11936) remote: js_error ((execjs):2659:12155) remote: croak ((execjs):2659:20622) remote: token_error ((execjs):2659:20759) remote: expect_token ((execjs):2659:20982) remote: expect ((execjs):2659:21120) remote: ctor.argnames ((execjs):2659:25664) remote: function_ ((execjs):2659:25728) remote: expr_atom ((execjs):2659:28965) remote: maybe_unary ((execjs):2659:31652) remote: expr_ops ((execjs):2660:404) remote: maybe_conditional ((execjs):2660:496) remote: maybe_assign ((execjs):2660:939) remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/execjs-2.6.0/lib/execjs/external_runtime.rb:39:in
exec'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/execjs-2.6.0/lib/execjs/external_runtime.rb:21:in eval' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/execjs-2.6.0/lib/execjs/external_runtime.rb:46:in
call'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/uglifier-2.7.2/lib/uglifier.rb:212:in run_uglifyjs' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/uglifier-2.7.2/lib/uglifier.rb:179:in
compile'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/uglifier_compressor.rb:52:in call' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/uglifier_compressor.rb:28:in
call'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:75:in call_processor' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:57:in
block in call_processors'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in reverse_each' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in
call_processors'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:134:in load_from_unloaded' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:60:in
block in load'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:318:in fetch_asset_from_dependency_cache' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:44:in
load'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:20:in block in initialize' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:47:in
load'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/base.rb:66:in find_asset' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/base.rb:73:in
find_all_linked_assets'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:142:in block in find' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/legacy.rb:114:in
block (2 levels) in logical_paths'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/path_utils.rb:225:in block in stat_tree' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/path_utils.rb:209:in
block in stat_directory'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/path_utils.rb:206:in each' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/path_utils.rb:206:in
stat_directory'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/path_utils.rb:224:in stat_tree' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/legacy.rb:105:in
each'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/legacy.rb:105:in block in logical_paths' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/legacy.rb:104:in
each'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/legacy.rb:104:in logical_paths' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:140:in
find'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:168:in compile' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.0.4/lib/sprockets/rails/task.rb:68:in
block (3 levels) in define'
remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/rake/sprocketstask.rb:147:in with_logger' remote: /tmp/build_089aae9379b515e85242da57b3a9066f/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.0.4/lib/sprockets/rails/task.rb:67:in
block (2 levels) in define'
remote: Tasks: TOP => assets:precompile
remote: (See full trace by running task with --trace)
remote: !
remote: ! Precompiling assets failed.
remote: !
remote:
remote: ! Push rejected, failed to compile Ruby app
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to pastie.
`
Hi,
I'm trying to translate the message but even on this simple example below does not work...
Still I get the message 'no existing match'
Does anyone know why ❓
<%= f.autocomplete_field :location_id, autocomplete_location_name_trainings_path, :"data-autocomplete-label" => "Sorry, nothing found.", update_elements: {}, class: 'form-control' %>
#or
<%= f.autocomplete_field :location_id, autocomplete_location_name_trainings_path, 'data-noMatchesLabel' => "Sorry, nothing found.", update_elements: {}, class: 'form-control' %>
First of all, big thanks for now taking care of this very valuable gem.
Please correct me if I'm wrong. I don't know how this actually works with the gems ...
It seems if I put in my Gemfile:
gem 'rails-jquery-autocomplete'
and do
bundle update rails-jquery-autocomplete'
I't looks for me that I do not get the current version. Is this still marked as rc or something?
You might want to bump the version number and make the current version the official one,
because there are a lot of very useful fixes in there.
The fix for simple_form was absolutely valuable as was the recent change for triggering the change event
Thank you for creating such useful gem.
And I would like to ask if I write something like that in my model.
scope : with_certain_state, ->(state) { where(:state => state) }
Is it possible to use it with the help of scopes in autocomplete?
Rails 4.2.0, Mysql 5.5
We have a search bar looking for telephone numbers. In our table, the field tn
is type bigint(20)
. I am able to use autocomplete to find a list of matching entries. When I try to click on an entry, I get the following the dev tools console:
TypeError: n.item.value.toLowerCase is not a function
autocomplete-rails.js:1:2138
Of course, the issue is the generated JS file trying to perform a string method on a bigint. I do not want to remove this method, as most of our search boxes contain alphanumeric characters. (This is the only instance, right now, of searching for a number.)
FWIW, here is the JavaScript I am using to submit the form when selecting a list item:
$('#did_tn').bind('railsAutocomplete.select', function(event, data) {
$('#did_select').submit();
});
I am constructing a page similar to jquery nested forms. It will be a table where you can click-to-add a telephone number. Upon adding a row, you will see a blank text field and a delete button.
My goal is to use Rails Autocomplete since it works with ActiveRecord. If the user has 100 telephone numbers, I would like them to search for text. Upon clicking the list item, the text field will contain the telephone number. When the form submits, it will be seen as a nested attribute, where the text entered matches a phone number's tn (not id).
From looking at the sample apps, it seems that this gem's main functionality is for searching, and redirecting to a new path. I do not want to redirect to a new path, but simply want to use ActiveRecord entries to populate the autocomplete drop down.
I read the source on jQuery UI's site, but it provides a static array of items to choose from within the Javascript.
Readme file contains example with require jquery-ui
. It would be great to require only needed ui components.
I have a nested form, where I add telephone numbers to a location. If any errors are present, the index is rendered. The nested fields are still present, but the contents of each field is gone. How do I retain the contents if the form fails?
I am using nested_forms
gem, rendering the fields_for
in a partial.
Ignore this. I later figured out ex-coworker had manually copied the javascript from a 2013 version in our system, so no matter how often I updated the gem, the site would load a 2-year-old version... Once I fixed that, it was all good...
Feel free to delete.
...Paul
rails-jquery-autocomplete (1.0.3)
jquery-rails (3.1.0)
jquery-ui-rails (5.0.5)
bootstrap_form (2.1.1)
Someone had the same issue, as seen in the forum post below:
https://railsforum.com/topic/1873-rails-4-autocomplete-gem/
A Proposal
has the attribute company_id
. Given there are many (100+) companies, I do not want a select box. Instead, using this gem would be most beneficial. Similar to the forum post, the autocomplete field also shares a name with an already-present attribute. A proposal also has a company_name
(soon to be deprecated, but nevertheless currently in database).
I have followed the instructions, and have no errors on my end. However, the autocomplete functionality is not working. When I attempt to create a new proposal and enter an existing company name, nothing happens. Could the shared name of attributes be conflicting with each other?
# config/routes.rb
resources :proposals do
get :autocomplete_company_name, on: :collection
end
# company.rb
def autocomplete_display
name
end
# proposals_controller.rb
autocomplete :company, :name, full: true, limit: 5, display_value: :autocomplete_display
// proposals/_form.html.haml
= bootstrap_nested_form_for @proposal, as: :proposal, url: url do |f|
// original:
// = f.collection_select :company_id, Company.all.to_a, :id, :name
= f.text_field :company_name, as: :autocomplete, url: autocomplete_company_name_proposals_path, id_element: '#company_id'
We have another app which uses this gem (successfully), and I noticed a few things:
application.js
includes jquery2
jquery2
autocomplete_field_tag
to search for an element, not attaching the result to a model.I am hesitant to upgrade the Rails version, but if necessary I will.
How can I search the ID column of a table in a postgresql database with this gem? There is nothing like "cast_to_text" present so the request on an integer column always fails because of the lower() function.
PG::UndefinedFunction: ERROR: function lower(integer) does not exist LINE 1: ...s"."id", "accounts"."name" FROM "accounts" WHERE (LOWER(acco... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. : SELECT accounts.id, "accounts"."id", "accounts"."name" FROM "accounts" WHERE (LOWER(accounts.id) ILIKE '10%') ORDER BY LOWER(accounts.id) ASC LIMIT 20
Hi all,
can somebody tell me where to fix this
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (autocomplete_patient_name, line 0)
http://localhost:3000/patient_symptoms/autocomplete_patient_name?term=doe
here are my code
controller patientsymptoms
class PatientSymptomsController < ApplicationController
autocomplete :patient, :name, :full => true
model patient
class Patient < ActiveRecord::Base
has_many :patient_symptoms
end
model patient_symptom
class PatientSymptom < ActiveRecord::Base
belongs_to :patient
end
javascript
//= require jquery
//= require jquery_ujs
// require turbolinks
//= require jquery-ui
//= require autocomplete-rails
//= require_tree .
_view form patient_symptoms
<%= simple_form_for(@patient_symptom) do |f| %>
<%= f.input :patient_name, :url => autocomplete_patient_name_patient_symptoms_path, :as => :autocomplete %>
<% end %>
routes
resources :patients
resources :patient_symptoms do
get :autocomplete_patient_name, :on => :collection
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.