Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add reader for association's child model's label method and use that in

FilteringMultiselect widget
  • Loading branch information...
commit 80c77687b35b414225ca4f3636f4974ad3945f85 1 parent cb926d3
@kaapa kaapa authored
View
2  app/controllers/rails_admin/main_controller.rb
@@ -247,7 +247,7 @@ def get_filter_hash(options)
case field.type
when :string, :text
statements << "(#{table_name}.#{key} LIKE ?)"
- values << value + "%"
+ values << value
when :boolean
statements << "(#{table_name}.#{key} = ?)"
values << (value == "true")
View
2  app/views/rails_admin/main/_form_filtering_multiselect.html.erb
@@ -33,7 +33,7 @@
$("#<%= "associations_#{name}" %>").filteringMultiselect({
<% if xhr %>
createQuery: function(query) {
- return { filter: { '<%= field.parent.with(:object => field.bindings[:object]).object_label_method %>': query } }
+ return { filter: { '<%= field.associated_label_method %>': query + '%' } }
},
source: "<%= rails_admin_list_path(field.associated_model_config.abstract_model.to_param, :compact => true) %>"
<% end %>
View
6 lib/rails_admin/config/fields/association.rb
@@ -42,6 +42,12 @@ def associated_model_config
@associated_model_config ||= RailsAdmin.config(association[:child_model])
end
+ # Reader for the association's child model object's label method
+ def associated_label_method
+ object = associated_model_config.abstract_model.new
+ associated_model_config.list.with(:object => object).object_label_method
+ end
+
# Reader for the association's child key
def child_key
association[:child_key].first
Please sign in to comment.
Something went wrong with that request. Please try again.