开发者

Rails 3 autocomplete crowdint plugin jquery

开发者 https://www.devze.com 2023-02-21 22:46 出处:网络
I wanted to set up textbox with autocomplete feature using crowdint plugin. So I made everything like in documentation.

I wanted to set up textbox with autocomplete feature using crowdint plugin. So I made everything like in documentation.

There is no error but text field works like regular text box.

I did include javascript for plugin

I did instal jquery-rails also When i type link responsible for autocomplte action: http://localhost:3000/general_items/autocomplete_items_type_name?term=b there appears found record. [{"id":1,"label":"book","value":"book"}] It means that autocomplete works but when i'm typing a word in text box nothing happens text box:

I checked and my browser, it doesn't send any request to server during typing a word...

any suggestions?

edit

so everything what i've done to set it up:

-----------------------plugin installation -------------------------

Installing

sudo gem install rails3-jquery-autocomplete

gem install jquery-rails

Include the gem on Gemfile

gem 'jquery-rails'
gem 'rails3-jquery-autocomplete'

Install it

bundle install

Run the generator

rails generate autocomplete

And include autocomplete-rails.js on my layouts

javascript_include_tag "autocomplete-rails.js"

----------------models-----------------------------

class GeneralItem < ActiveRecord::Base
  belongs_to :theuser , :foreign_key => "user_id"
  belongs_to :items_type , :foreign_key => "type_id"  
  #more code there...

end


class ItemsType < ActiveRecord::Base 

has_many :theitems 
has_many :general_items

accepts_nested_attributes_for :general_items, :a开发者_StackOverflowllow_destroy => true


end

table items_type has columns: id, name, created_at, modified_at

-------------controllers---------------------------

class GeneralItemsController < ApplicationController
  autocomplete :items_type, :name

more code there...

-------------views----------------------------

layoute file:

<!DOCTYPE html>
<html>
<head>
  <title>Library</title>
  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :defaults %>
  <%=  javascript_include_tag "autocomplete-rails.js" %>

  <%= csrf_meta_tag %>

_form.html.erb:

<%= form_for(@general_item) do |f| %>


  <div class="field">
    <%= f.label :user_id %><br />
    <%= f.text_field :user_id %>
  </div>
  <div class="field">
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </div>
   <div class="field">
    <%= f.label :type %><br />
    <%= f.autocomplete_field :descr_english, autocomplete_items_type_name_general_items_path %>

  </div>

more code there...

as i wrote it seems that plugin is working but application doesn't send querys dynamicly during typing leters in autocomplete_field...


Sounds like you're missing the form configuration or your autocomplete.js file is actually missing, if you didn't use the generator from the gem to install it.

Do you have lines like this in your form?

form_for @product do |f|
  f.autocomplete_field :brand_name, autocomplete_brand_name_products_path
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号