Skip to content

Dependant select boxes - sending no value when mutliple select box is empty #7

@zorec

Description

@zorec

Given the following schema project has_many tasks. Employee has_many projects and has_many tasks through projects.

class Employee < ActiveRecord::Base
  has_many :projects, inverse_of: :employee
  has_many :tasks, through: :projects

  rails_admin do
    edit do
      field :projects
      field :tasks do
        options_source_params do
          { "f[project_id_in]" => bindings[:object].try(:project_ids) || [-1] }
        end
        html_attributes do
        { data: { 
          # set project's field as dependent select box
          "dependant-filteringselect" => "field=project_ids",

          # post parameters
          "dependant-param" => "f[project_id_in]" }
        }
        end
      end
      field :name
      # other fields
    end
  end

The problem is when project field is empty. Then no project_id is sent in options request to TasksController. This means that all tasks are shown

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