Skip to content

JS enhancements not active on new sub-records #49

@pablobm

Description

@pablobm

When a NestedHasMany field in turn contains an associative field, such as a BelongsTo, the JS enhancements from Administrate do not apply correctly when adding new sub-records.

This is an example model:

class Recipe < ApplicationRecord
  has_many :recipe_ingredients
  has_many :ingredients, through: :recipe_ingredients

  accepts_nested_attributes_for(
    :recipe_ingredients,
    reject_if: :all_blank,
    allow_destroy: true
  )
end

And the corresponding dashboard:

require "administrate/base_dashboard"

class RecipeDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    id: Field::Number,
    name: Field::String,
    recipe_ingredients: Field::NestedHasMany.with_options(
      skip: [:recipe]
    ),
  }.freeze

  # ...
end

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 of RecipeIngredient will be enhanced with Selectize (as provided by Administrate by default):

Two sub-forms in a NestedHasMany field: the first is enhanced with Selectize, while the second isn't

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions