Sha256: 105b6fc17c7fb5020649160b261e558a5ae5ee89520fc7281a579767958b565d

Contents?: true

Size: 1.82 KB

Versions: 29

Compression:

Stored size: 1.82 KB

Contents

class ActiveScaffold::Bridges::Chosen
  module Helpers
    def self.included(base)
      base.class_eval do
        include FormColumnHelpers
        include SearchColumnHelpers
      end
    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.plural_association?
          associated_options, select_options = active_scaffold_plural_association_options(column)
          options = {:selected => associated_options.collect(&:id), :include_blank => as_(:_select_)}

          html_options.update(:multiple => true).update(column.options[:html_options] || {})
          options.update(column.options)
          html_options[:name] = "#{html_options[:name]}[]" if html_options[:multiple] == true && !html_options[:name].to_s.ends_with?('[]')

          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
        active_scaffold_search_select(column, options)
      end
    end
  end
end

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

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
active_scaffold-3.4.43 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.42 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.41.1 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.41 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.40 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.39 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.38 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.37 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.36 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.35 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.34 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.33 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.32 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.31 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.30 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.29 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.28 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.27 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.26 lib/active_scaffold/bridges/chosen/helpers.rb
active_scaffold-3.4.25 lib/active_scaffold/bridges/chosen/helpers.rb