I would love to add custom field which uses ChosenRails gem.
I have generated custom field with commad:
rails generate administrate:field chosen
then modified form partial for field:
<div class="field-unit__label">
<%= f.label field.attribute %>
</div>
<div class="field-unit__field">
<%= f.select field.attribute,
User.all.map { |u| [u.name, u.id] },
{ include_blank: true },
{ class: 'chosen-select' }
%>
</div>
and changed attribute type in user_dashboard.rb
ATTRIBUTE_TYPES = {
id: Field::Number,
email: Field::String,
name: Field::String,
surname: Field::String,
manager: Field::ChosenField.with_options(searchable: false),
created_at: Field::DateTime,
updated_at: Field::DateTime,
}.freeze
After this when I try to load my form normal select list appears. I have tried to do the same outside the admin scope and it works fine.
Is there any possibility to make ChosenRails gem work?
@Reedian as an engine I don't think administrate will load in your application's javascript.
It does provide a yield(:javascript) though.
So in your field partial you should do
<%= content_for :javascript do %>
# whatever js you need for chosen rails
<% end %>
@Reedian Did the solution suggested by @j-dexx solve your problem? If so, would you consider this issue resolved?
@carlosramireziii yes, it sloved my problem. Thanks for the support.
Glad to hear it! You are very welcome :)
Most helpful comment
@Reedian as an engine I don't think administrate will load in your application's javascript.
It does provide a
yield(:javascript)though.So in your field partial you should do