Imagine the classic department, employee relation construct (Employees,
Departments tables)
A department can have a number of employees, employees must belong to
one department, there are many departments)
I have two divs one contains a number of check boxes with the various
departments
<div finder>
London [x] LA [x]
Paris [x] Sydney [x]
Tokyo [x] Rome [x]
New York [x] Bangalore [x]
</div>
<div employee_list>
Bob | London
Remy | Paris
Chuck | New York
Jen | Rome
Ken | Tokyo
Paul | London
</div>
The number of departments are variable and can change over time, so
"hard" coding observers are impossible
---Controller---
@departments = Department.find(:all)
---View-----
<% for dept in @departments
<td align="right">
<% dept.dname
<% check_box_name = "dept[" + dept.id.to_s + "][query]"
%>
<%= check_box_tag ( check_box_name,dept.id.to_s, :checked => true ) %>
<%= observe_field (check_box_name,
:frequency => 0.5,
:update => :employee_list ,
:url => { :action => :filter_depart},
:with => "''exclude='' + escape(" +
dept.id.to_s + ") +
''&checked='' + escape(value)" )
%>
</td>
---
This actually works well when the users clicks (unchecks or checks) on
the check box of a department the controller action "filter_depart" is
called and by checking the parameter of "exclude" and the value of
"checked" it is possible to determine wich dept id was checked or
unchecked and the query to employee table can be filtered on this info.
In the example above if the user unchecks London, Bob and Paul will
disappear from the employee listing. Happy ROR and AJAX developer.
The problem is that if the user then unchecks another check box eg.
Rome, the filter_depart controller action is called and Rome, Jen is
removed. However London ( Bob and Paul) employees are retrived even if
Londons check box remains unchecked.
The reason is that the controller action filter_depart is called by the
observer upon the change of a single check box and the value parameters
exclude and checked apply only to that single check box rather than the
array of check boxes.
Is there anyway to have an observer field(s) notice any change to any
field(s) particularly those generated with the standard check_box_tag
processing and lauch a "submit_to_remote" , which will mean that all
params of the form (including all check boxes values) are available to a
given controller?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---