I'm trying to set up a form that among other things includes two related select drop-downs, where the choice the user makes for the first select will then re-load the second select list with the relevant options.
The problem I'm having is that by re-inserting the select using observe_field, the inserted select's value never gets sent with the rest of the form data. Is this a known problem and is there a way around it?
My edituser.rhtml
The two selects in question being permission_controller and permission_action. The observe_field submits to controller_action_list to create the new select:Code:<h2>Edit user <%= @user.firstname + ' ' + @user.lastname %></h2> <h3><%= @user.firstname %>'s permissions</h3> <%= form_tag :action => 'addpermission' %> <table id="permissions"> <thead> <tr> <th>Controller</th> <th>Action</th> <th>ID</th> <th>Allow/Disallow</th> <th>Moderate</th> </tr> </thead> <tbody> <% for permission in @user.permissions %> <tr> <td><%= link_to permission.controller, :controller => permission.controller %></td> <td><%= (permission.action == '') ? link_to('All', :controller => permission.controller) : link_to(permission.action, :controller => permission.controller, :action => permission.action) %></td> <td><%= (permission.target_id == 0) ? 'All' : permission.target_id %></td> <td> <%= (permission.allow == 1) ? 'Allowed' : '' %> <%= (permission.disallow == 1) ? 'Disallowed' : '' %> </td> <td><%= (permission.moderated == 1) ? 'Yes' : 'No' %></td> </tr> <% end %> <tr> <td colspan="5"> <h4>Add a permission</h4> <%= hidden_field 'permission', 'user_id', :value => params[:id] %> </td> </tr> <tr> <td><%= select 'permission', 'controller', @cs %></td> <td id="actionlist"> <%= select 'permission', 'action', [ ['Choose a controller first', 'debug'] ]%> </td> <td><%= text_field 'permission', 'target_id', :size => 4 %></td> <td><%= select 'other', 'allowdisallow', %w{ Allow Disallow } %></td> <td><%= select 'permission', 'moderated', [ ['No', 0], ['Yes', 1] ] %></td> </tr> <tr> <td colspan="5"> <%= submit_tag 'Create permission' %> </td> </tr> </tbody> </table> <%= end_form_tag%> <%= observe_field("permission_controller", :frequency => 0.5, :update => "actionlist", :url => { :action => 'controller_action_list' }, :with => "'ctrl='+value") %>
controller_action_list:
And controller_action_list.rhtmlCode:def controller_action_list if @params['ctrl'] != 'Please choose a controller' # turn back into class name ctrl = params['ctrl'].sub(/[a-z]/) {|match| match.upcase} ctrl = ctrl.gsub(/_([a-z])/) {|match| match.upcase.sub(/_/, '')} ctrl += "Controller" @c = Object.const_get(ctrl).new end render(:layout => false) end
If the form is submitted without the observe_field being triggered, then the permissions[action] value is sent fine. Once the select has been re-written that form attribute simply never gets sent.Code:<% if @params['ctrl'] != 'Please choose a controller' %> <select name="permission[action]" id="permission_action">" <option value="">All <%= @c.controller_name %> actions</option> <% for m in @c.public_methods(false) %> <option value="<%= m %>"><%= m %></option> <% end %> </select> <% else %> <select name="permission[action]" id="permission_action"> <option value="">Choose a controller first</option> </select> <% end %>




Bookmarks