Sha256: 6a294dc52d5402ee7f151e7794fbebc2c761806762bf6c5c6b4482bd43bb9568

Contents?: true

Size: 1.91 KB

Versions: 24

Compression:

Stored size: 1.91 KB

Contents

require 'active_support/concern'

class ActiveScaffold::Bridges::Chosen
  module Helpers
    extend ActiveSupport::Concern
    included do
      include FormColumnHelpers
      include SearchColumnHelpers
    end

    module FormColumnHelpers
      # requires RecordSelect plugin to be installed and configured.
      def active_scaffold_input_chosen(column, html_options)
        html_options[:class] << ' chosen'
        if column.association&.collection?
          record = html_options.delete(:object)
          associated_options, select_options = active_scaffold_plural_association_options(column, record)
          options = {selected: associated_options.collect(&:id), include_blank: as_(:_select_), object: record}

          html_options.update(multiple: true).update(column.options[:html_options] || {})
          options.update(column.options)
          active_scaffold_select_name_with_multiple html_options

          if (optgroup = options.delete(:optgroup))
            select(:record, column.name, active_scaffold_grouped_options(column, select_options, optgroup), options, html_options)
          else
            collection_select(:record, column.name, select_options, :id, column.options[:label_method] || :to_label, options, html_options)
          end
        else
          active_scaffold_input_select(column, html_options)
        end
      end
    end

    module SearchColumnHelpers
      def active_scaffold_search_chosen(column, options)
        options[:class] << ' chosen'
        active_scaffold_search_select(column, options)
      end

      def active_scaffold_search_multi_chosen(column, options)
        options[:class] << ' chosen'
        options[:multiple] = true
        options[:'data-placeholder'] = column.options[:placeholder] || as_(:_select_)
        active_scaffold_search_select(column, options)
      end
    end
  end
end

ActionView::Base.class_eval { include ActiveScaffold::Bridges::Chosen::Helpers }

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
active_scaffold-3.7.0 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.20 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.19 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.17 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.15 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.14 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.13 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.12 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.11.1 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.11 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.10 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.9 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.8 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.6 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.5 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.4.1 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.4 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.3 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.2 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.6.1 lib/active_scaffold/bridges/chosen/helpers.rb