Open pablobm opened 3 years ago
Add this code:
<%# app/views/admin/application/_javascript.html.erb %>
<%= javascript_tag do %>
$('.field-unit--nested').on('cocoon:after-insert', function() {
$('.field-unit--belongs-to select').selectize({});
});
<% end %>
I tried following @dadachi's suggestion, but it instead removed all of the JS.
I think the step I missed was to first copy app/views/admin/application/_javascript.html.erb
from the administrate source (which you can do manually, or via rails generate administrate:views:layout
), and then add the code above.
I wonder if this could be done in the gem around here? https://github.com/nickcharlton/administrate-field-nested_has_many/blob/94500b6355a291f3ae604333561f1b3e0b57df10/lib/administrate/field/nested_has_many.rb#L12-L14
Did anyone manage to fix this yet ?
When a
NestedHasMany
field in turn contains an associative field, such as aBelongsTo
, the JS enhancements from Administrate do not apply correctly when adding new sub-records.This is an example model:
And the corresponding dashboard:
When creating or editing a recipe, if I click to "Add Recipe Ingredient", the new sub-form for
RecipeIngredient
will have a plain select dropdown. However pre-existing records ofRecipeIngredient
will be enhanced with Selectize (as provided by Administrate by default):