Skip to content

Checkbox List

Checkbox List field

The CheckboxList field renders a list of checkboxes for selecting multiple values from a finite set of options.

Use it when the available options are already known and users should see the choices directly instead of opening a select.

ruby
field :team_member_ids,
  as: :checkbox_list,
  options: -> {
    User.active.order(:name).map do |user|
      {
        id: user.id,
        title: user.name,
        avatar_url: user.avatar_url,
        image_format: :circle,
        description: user.email
      }
    end
  },
  inline_search: true

The field submits an array of selected option ids. This works well with Rails collection writers like team_member_ids=.

Options

options

The options attribute is required and accepts an array or a proc that returns an array.

Each option should be a hash with these keys:

KeyDescription
idThe submitted value for the checkbox
titleThe visible title
descriptionOptional supporting text shown below the title
avatar_url or image_urlOptional image shown before the title
avatar_alt or image_altOptional alt text for the image
image_formatOptional image shape. Use :circle, :rounded, or :square. Defaults to :circle
ruby
field :role_ids,
  as: :checkbox_list,
  options: [
    {id: 1, title: "Admin", description: "Can manage the account"},
    {id: 2, title: "Editor", description: "Can update content"},
    {id: 3, title: "Viewer", description: "Can read content"}
  ]

Computed options run inside Avo::ExecutionContext, so they have access to record, resource, view, field, params, request, view_context, and the other execution context helpers.

ruby
field :user_ids,
  as: :checkbox_list,
  options: -> {
    users = User.order(:name)

    users.map do |user|
      {
        id: user.id,
        title: user.name,
        avatar_url: user.avatar_url,
        description: user.email
      }
    end
  }

Set inline_search: true to add a client-side search input above the checkbox list.

The search filters the options that were already rendered on the page. It does not make server requests, so use it for small and medium option sets.

ruby
field :team_member_ids,
  as: :checkbox_list,
  options: -> { User.active.order(:name).map { |user| {id: user.id, title: user.name} } },
  inline_search: true

Default

false

Possible values

true, false