diff options
| author | Koza <[email protected]> | 2022-07-11 10:17:27 +0200 |
|---|---|---|
| committer | Stefan Daschek <[email protected]> | 2022-07-12 13:11:24 +0200 |
| commit | e975a2451ae3c5f6eb62bfbfea33be3bb9f2cb14 (patch) | |
| tree | 963e91ace302a893188d1e1a79d91958e5d11996 | |
| parent | b9b59ab3e115cde48252fb7f7eec741c20a31ea4 (diff) | |
| download | caxlsx-e975a2451ae3c5f6eb62bfbfea33be3bb9f2cb14.tar.gz caxlsx-e975a2451ae3c5f6eb62bfbfea33be3bb9f2cb14.zip | |
Add `hideDropDown` alias for `showDropDown` setting, as the latter is confusing to use (because its logic seems inverted).
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | examples/list_validation_example.md | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/data_validation.rb | 29 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_data_validation.rb | 27 |
4 files changed, 48 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index cf355f8f..6791d637 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ CHANGELOG --------- - **Unreleased** + - [PR #155](https://github.com/caxlsx/caxlsx/pull/155) - Add `hideDropDown` alias for `showDropDown` setting, as the latter is confusing to use (because its logic seems inverted). - [PR #143](https://github.com/caxlsx/caxlsx/pull/143) - Add setting `sort_on_headers` for pivot tables - [PR #132](https://github.com/caxlsx/caxlsx/pull/132) - Remove monkey patch from Object#instance_values - [PR #139](https://github.com/caxlsx/caxlsx/pull/139) - Sort archive entries for correct MIME detection with `file` command diff --git a/examples/list_validation_example.md b/examples/list_validation_example.md index 7c44fc2c..cf375c08 100644 --- a/examples/list_validation_example.md +++ b/examples/list_validation_example.md @@ -40,7 +40,7 @@ wb.add_worksheet(name: 'Basic Worksheet') do |sheet| sheet.add_data_validation('B3:B3', type: :list, formula1: '"north, east, south, west"', - showDropDown: true, # Note that this does in fact *hide* the dropdown. + hideDropDown: true, showErrorMessage: true, errorTitle: '', error: 'Allowed values: north, east, south, west', diff --git a/lib/axlsx/workbook/worksheet/data_validation.rb b/lib/axlsx/workbook/worksheet/data_validation.rb index 835b5b33..71f9bbe6 100644 --- a/lib/axlsx/workbook/worksheet/data_validation.rb +++ b/lib/axlsx/workbook/worksheet/data_validation.rb @@ -13,11 +13,12 @@ module Axlsx # @option options [Boolean] allowBlank - A boolean value indicating whether the data validation allows the use of empty or blank entries. # @option options [String] error - Message text of error alert. # @option options [Symbol] errorStyle - The style of error alert used for this data validation. - # @option options [String] errorTitle - itle bar text of error alert. + # @option options [String] errorTitle - Title bar text of error alert. # @option options [Symbol] operator - The relational operator used with this data validation. # @option options [String] prompt - Message text of input prompt. # @option options [String] promptTitle - Title bar text of input prompt. - # @option options [Boolean] showDropDown - A boolean value indicating whether to display a dropdown combo box for a list type data validation + # @option options [Boolean] showDropDown - A boolean value indicating whether to display a dropdown combo box for a list type data validation. Be careful: It has an inverted logic, false shows the dropdown list! You should use hideDropDown instead. + # @option options [Boolean] hideDropDown - A boolean value indicating whether to hide the dropdown combo box for a list type data validation. Defaults to `false` (meaning the dropdown is visible by default). # @option options [Boolean] showErrorMessage - A boolean value indicating whether to display the error alert message when an invalid value has been entered, according to the criteria specified. # @option options [Boolean] showInputMessage - A boolean value indicating whether to display the input prompt message. # @option options [String] sqref - Range over which data validation is applied, in "A1:B2" format. @@ -121,13 +122,22 @@ module Axlsx # Show drop down # A boolean value indicating whether to display a dropdown combo box for a list type data - # validation. Be careful: false shows the dropdown list! + # validation. Be careful: It has an inverted logic, false shows the dropdown list! # Available for type list # @see type # @return [Boolean] # default false attr_reader :showDropDown + # Hide drop down + # A boolean value indicating whether to hide a dropdown combo box for a list type data + # validation. Defaults to `false` (meaning the dropdown is visible by default). + # Available for type list + # @see type + # @return [Boolean] + # default false + alias :hideDropDown :showDropDown + # Show error message # A boolean value indicating whether to display the error alert message when an invalid # value has been entered, according to the criteria specified. @@ -195,7 +205,18 @@ module Axlsx def promptTitle=(v); Axlsx::validate_string(v); @promptTitle = v end # @see showDropDown - def showDropDown=(v); Axlsx::validate_boolean(v); @showDropDown = v end + def showDropDown=(v) + warn 'The `showDropDown` has an inverted logic, false shows the dropdown list! You should use `hideDropDown` instead.' + Axlsx::validate_boolean(v) + @showDropDown = v + end + + # @see hideDropDown + def hideDropDown=(v) + Axlsx::validate_boolean(v) + # It's just an alias for the showDropDown attribute, hideDropDown should set the value of the original showDropDown. + @showDropDown = v + end # @see showErrorMessage def showErrorMessage=(v); Axlsx::validate_boolean(v); @showErrorMessage = v end diff --git a/test/workbook/worksheet/tc_data_validation.rb b/test/workbook/worksheet/tc_data_validation.rb index fbf31682..12fee6ef 100644 --- a/test/workbook/worksheet/tc_data_validation.rb +++ b/test/workbook/worksheet/tc_data_validation.rb @@ -1,11 +1,13 @@ # encoding: UTF-8 require 'tc_helper.rb' - +require 'support/capture_warnings' class TestDataValidation < Test::Unit::TestCase + include CaptureWarnings + def setup #inverse defaults - @boolean_options = { :allowBlank => false, :showDropDown => true, :showErrorMessage => false, :showInputMessage => true } + @boolean_options = { :allowBlank => false, :hideDropDown => true, :showErrorMessage => false, :showInputMessage => true } @nil_options = { :formula1 => 'foo', :formula2 => 'foo', :errorTitle => 'foo', :operator => :lessThan, :prompt => 'foo', :promptTitle => 'foo', :sqref => 'foo' } @type_option = { :type => :whole } @error_style_option = { :errorStyle => :warning } @@ -118,8 +120,21 @@ class TestDataValidation < Test::Unit::TestCase end def test_showDropDown - assert_raise(ArgumentError) { @dv.showDropDown = "foo´" } - assert_nothing_raised { @dv.showDropDown = false } + warnings = capture_warnings do + assert_raise(ArgumentError) { @dv.showDropDown = "foo´" } + assert_nothing_raised { @dv.showDropDown = false } + assert_equal(@dv.showDropDown, false) + end + + assert_equal 2, warnings.size + assert_includes warnings.first, 'The `showDropDown` has an inverted logic, false shows the dropdown list! You should use `hideDropDown` instead.' + end + + def test_hideDropDown + assert_raise(ArgumentError) { @dv.hideDropDown = "foo´" } + assert_nothing_raised { @dv.hideDropDown = false } + assert_equal(@dv.hideDropDown, false) + # As hideDropdown is just an alias for showDropDown, we should test the original value too assert_equal(@dv.showDropDown, false) end @@ -182,7 +197,7 @@ class TestDataValidation < Test::Unit::TestCase @ws.add_data_validation("A1", { :type => :list, :formula1 => 'A1:A5', :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values from list', :errorStyle => :stop, :showInputMessage => true, :promptTitle => 'Be carful!', - :prompt => 'Only values from list', :showDropDown => true}) + :prompt => 'Only values from list', :hideDropDown => true}) doc = Nokogiri::XML.parse(@ws.to_xml_string) @@ -233,7 +248,7 @@ class TestDataValidation < Test::Unit::TestCase @ws.add_data_validation("B1", { :type => :list, :formula1 => 'A1:A5', :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values from list', :errorStyle => :stop, :showInputMessage => true, :promptTitle => 'Be carful!', - :prompt => 'Only values from list', :showDropDown => true}) + :prompt => 'Only values from list', :hideDropDown => true}) doc = Nokogiri::XML.parse(@ws.to_xml_string) |
