Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Cascading combo Box using Chained plugin.


  • Please log in to reply
1 reply to this topic

#1 jschrock1

jschrock1

    Dispatcher

  • Members
  • 45 posts
  • LocationIndianapolis

Posted 21 November 2013 - 10:12 PM

I've been struggling to implement a cascading combo box.  I;ve tried a number of implementations I found on various forms, all in the end fail mostly cause Im just getting one thing or another in the examples.

 

I did however find what appears to be the simplest approach, using chained plugin, I implemented it and got a syntax error on a line that Im not familiar with..  See the highlighted line below  At the end I will place the error message.  can anybody help me with this line....  I'd kiss the floow im walking on if I can get this error resolved AND I get my cascading combo box.  I've read of some gems to use, however Im still quite a newbie and though this implementation may be best for me at this time...

 

@rooms = JobCategory.all
    @rooms_for_dropdown = []
    @rooms.each do |i|
      @rooms_for_dropdown = @rooms_for_dropdown << [i.name,i.id]
    end
        
    @devices = JobSubCategory.all
    @devices_for_dropdown = []
    @devices.each do |i|
      @devices_for_dropdown = @devices_for_dropdown << [i.name,i.id,{:class => i.@room.id}]
    end

 

C:/RailsInstaller/rails_project/werkhub_app/app/controllers/users_controller.rb:44: syntax error, unexpected tIVAR ...[i.name,i.id,{:class => i.@room.id}] ... ^ C:/RailsInstaller/rails_project/werkhub_app/app/controllers/users_controller.rb:44: syntax error, unexpected '}', expecting keyword_end ...ame,i.id,{:class => i.@room.id}] ... ^ C:/RailsInstaller/rails_project/werkhub_app/app/controllers/users_controller.rb:131: syntax error, unexpected $end, expecting keyword_end

 

The auther of this code snipet explained why we are using the class => i....  here is his comments

 

You will note that I've used :class in the array of devices that I'm returning - this is essential for using the jQuery chained plugin. What is happening is that we are actually returning an array of all devices available to the user, but each of the options has a class according to what room it belongs to. This allows the plugin to dynamically hide the options that are not relevant, without making an AJAX call (it should be noted that if Javascript happens to be turned off, all options will be available - while this wouldn't be ideal, it means that the application won't be completely broken without JS).



#2 jschrock1

jschrock1

    Dispatcher

  • Members
  • 45 posts
  • LocationIndianapolis

Posted 22 November 2013 - 02:04 PM

I've been struggling to implement a cascading combo box.  I;ve tried a number of implementations I found on various forms, all in the end fail mostly cause Im just getting one thing or another in the examples.

 

I did however find what appears to be the simplest approach, using chained plugin, I implemented it and got a syntax error on a line that Im not familiar with..  See the highlighted line below  At the end I will place the error message.  can anybody help me with this line....  I'd kiss the floow im walking on if I can get this error resolved AND I get my cascading combo box.  I've read of some gems to use, however Im still quite a newbie and though this implementation may be best for me at this time...

 

@rooms = JobCategory.all
    @rooms_for_dropdown = []
    @rooms.each do |i|
      @rooms_for_dropdown = @rooms_for_dropdown << [i.name,i.id]
    end
        
    @devices = JobSubCategory.all
    @devices_for_dropdown = []
    @devices.each do |i|
      @devices_for_dropdown = @devices_for_dropdown << [i.name,i.id,{:class => i.@room.id}]
    end

 

C:/RailsInstaller/rails_project/werkhub_app/app/controllers/users_controller.rb:44: syntax error, unexpected tIVAR ...[i.name,i.id,{:class => i.@room.id}] ... ^ C:/RailsInstaller/rails_project/werkhub_app/app/controllers/users_controller.rb:44: syntax error, unexpected '}', expecting keyword_end ...ame,i.id,{:class => i.@room.id}] ... ^ C:/RailsInstaller/rails_project/werkhub_app/app/controllers/users_controller.rb:131: syntax error, unexpected $end, expecting keyword_end

 

The auther of this code snipet explained why we are using the class => i....  here is his comments

 

You will note that I've used :class in the array of devices that I'm returning - this is essential for using the jQuery chained plugin. What is happening is that we are actually returning an array of all devices available to the user, but each of the options has a class according to what room it belongs to. This allows the plugin to dynamically hide the options that are not relevant, without making an AJAX call (it should be noted that if Javascript happens to be turned off, all options will be available - while this wouldn't be ideal, it means that the application won't be completely broken without JS).

 

OK, I've found another solution that works great,  this link is:

http://www.chasepurs...the-client-side






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users