-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filtering Field::HasMany #1988
Comments
I also had to go with modifying the partial. |
Yeah, I don't think there's a way to do this at the moment. Perhaps it would be a good idea to add a new option to the field that allows for this. It would probably have to modify administrate/lib/administrate/field/has_many.rb Lines 85 to 92 in b3bb0a3
Perhaps someone would like to volunteer a PR? |
I prepared a very rudimentary implementation here, but it's not that thought out. It would be probably better to pass scopes rather than plain |
Yup, that's the sort of thing we would need. I think it could be done better if it accepted a administrate/lib/administrate/field/select.rb Lines 16 to 23 in 9071a7e
|
Hi! Stumbled upon this issue while needing filtering on Based on current implementation for |
Found this extension that can achieve the same thing: https://github.com/XPBytes/administrate-field-scoped_has_many |
it would be great to just get this in here because that extension doesnt provide support for nice many-to-many fields etc, its just an awful html multiselect which is impossible to use for large options |
@9mm FWIW I ended up going back to default field and using this approach to scope results: |
Awesome, thanks! |
I ended up disliking the Dropdown component used in I tried coming back to using the OG I ended up MonkeyPatching to support a module Administrate
module Field
class HasMany < Associative
private
def candidate_resources
puts options[:scope]
scope = options[:scope] ? options[:scope].call(self) : associated_class.all
scope = scope.includes(*options.fetch(:includes)) if options.key?(:includes)
scope
end
end
end
end |
See, I've got a lot of users with different characteristics on my app. For example, they all have a
role
, which is an enum. Some models have references to users, but some of them have restrictions related to roles. For example, you can't select an user who's aguess
to be theeditor
on a post. I've got all of that figured out via validations, but it would be nice to have it reflected on the interface. As if, when I start editing theeditors
attribute on a certain post, only users with the roleauthor
oradmin
appear as options.Passing some kind of filter (maybe a function) to the field on
user_dashboard.rb
would be nice.I could just filter it out during rendering (modifying the partial for
Field::HasMany
), but that's not nice to do if I want to do it on a lot of dashboards with many different conditions. A minimal example on how to do this would be extremely useful to me.The text was updated successfully, but these errors were encountered: