diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 70b56a338..f0d6ca99c 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -5,6 +5,7 @@ - Add buttons to check all and uncheck all on :select form ui for collection associations, and draggable lists (active_scaffold_checkbox_list). - Add hidden field with locking column in base_form partial for persisted records automatically, if model uses optimistic locking. - Add on_stale_object_error when StaleObjectError is rescued, to allow customization. +- Fix search_ui :select_multiple, which was broken when operator select was added. = 3.7.8 - Rollback previous behaviour when submitting empty values, broken when default_value was added. Default value set in column is not used when trying to save empty value, DB default is used in that case, and save NULL when string is empty, as before. diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index 737cd306a..9f5267d4a 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -974,6 +974,11 @@ font-size: 100%; float:left; } +.active-scaffold .search .search_range .as_search_range_option { + vertical-align: top; + margin-right: 5px; +} + .active-scaffold .tabbed .nav-tabs { border-bottom: 1px solid #ddd; padding-left: 0; @@ -1027,7 +1032,6 @@ font-size: 100%; display: block; } - .as_touch a.inline-adapter-close { width: 25px; height: 27px; diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index a99d6dc8e..827ead37a 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -165,7 +165,11 @@ def condition_for_search_ui(column, value, like_pattern, search_ui) when :integer, :decimal, :float condition_for_numeric(column, value) when :string, :range - condition_for_range(column, value, like_pattern) + if value.is_a?(Hash) + condition_for_range(column, value, like_pattern) + else + condition_for_single_value(column, value, like_pattern) + end when :date, :time, :datetime, :timestamp condition_for_datetime(column, value) when :select, :select_multiple, :draggable, :multi_select, :country, :usa_state, :chosen, :multi_chosen @@ -176,12 +180,7 @@ def condition_for_search_ui(column, value, like_pattern, search_ui) ['%s in (?)', values] if values.present? end else - if column.text? - value = column.active_record? ? column.active_record_class.sanitize_sql_like(value) : value - ["%s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] - else - ['%s = ?', ActiveScaffold::Core.column_type_cast(value, column.column)] - end + condition_for_single_value(column, value, like_pattern) end end @@ -199,16 +198,21 @@ def condition_for_numeric(column, value) end end + def condition_for_single_value(column, value, like_pattern = nil) + if column.text? + value = column.active_record? ? column.active_record_class.sanitize_sql_like(value) : value + ["%s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] + else + ['%s = ?', ActiveScaffold::Core.column_type_cast(value, column.column)] + end + end + def condition_for_range(column, value, like_pattern = nil) - if !value.is_a?(Hash) - if column.text? - value = column.active_record? ? column.active_record_class.sanitize_sql_like(value) : value - ["%s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] - else - ['%s = ?', ActiveScaffold::Core.column_type_cast(value, column.column)] - end - elsif ActiveScaffold::Finder::NULL_COMPARATORS.include?(value[:opt]) + if ActiveScaffold::Finder::NULL_COMPARATORS.include?(value[:opt]) condition_for_null_type(column, value[:opt], like_pattern) + elsif value[:from].is_a?(Array) # opt can be only = + from = Array(value[:from]).select(&:present?) + ['%s in (?)', from] if from.present? elsif value[:from].blank? nil elsif ActiveScaffold::Finder::STRING_COMPARATORS.values.include?(value[:opt]) diff --git a/lib/active_scaffold/helpers/human_condition_helpers.rb b/lib/active_scaffold/helpers/human_condition_helpers.rb index 14f46c2da..5253cacd9 100644 --- a/lib/active_scaffold/helpers/human_condition_helpers.rb +++ b/lib/active_scaffold/helpers/human_condition_helpers.rb @@ -108,7 +108,8 @@ def active_scaffold_human_condition_select(column, associated) return active_scaffold_human_condition_range(column, associated) unless associated['opt'] == '=' associated = associated['from'] end - associated = [associated].compact unless associated.is_a? Array + associated = [associated] unless associated.is_a? Array + associated = associated.select(&:present?) if column.association method = column.options[:label_method] || :to_label associated = column.association.klass.where(:id => associated.map(&:to_i)).map(&method) @@ -122,6 +123,7 @@ def active_scaffold_human_condition_select(column, associated) as_(:association, :scope => :human_conditions, :column => attribute, :value => associated.join(', ')) end alias active_scaffold_human_condition_multi_select active_scaffold_human_condition_select + alias active_scaffold_human_condition_select_multiple active_scaffold_human_condition_select alias active_scaffold_human_condition_record_select active_scaffold_human_condition_select alias active_scaffold_human_condition_chosen active_scaffold_human_condition_select alias active_scaffold_human_condition_multi_chosen active_scaffold_human_condition_select diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index f44b8b9a9..a176e5791 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -98,7 +98,7 @@ def active_scaffold_search_multi_select(column, options, ui_options: column.opti def active_scaffold_search_select(column, html_options, options = {}, ui_options: column.options) record = html_options.delete(:object) associated = html_options.delete :value - if include_null_comparators?(column) + if include_null_comparators?(column, ui_options: ui_options) range_opts = html_options.slice(:name, :id) range_opts[:opt_value], associated, = field_search_params_range_values(column) operators = active_scaffold_search_select_comparator_options(column, ui_options: ui_options)