summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorJan-Hendrik Hühne <[email protected]>2012-05-24 09:38:53 +0200
committerJan-Hendrik Hühne <[email protected]>2012-05-24 09:38:53 +0200
commitb2c5ed169cbce41ed9e304ddcc13e841f465adb0 (patch)
tree36bd86e7dc01f3631acbe991ac2b999719888a93 /lib
parenta2513af2822a6341b3f3de5fca13d93ea7473117 (diff)
downloadcaxlsx-b2c5ed169cbce41ed9e304ddcc13e841f465adb0.tar.gz
caxlsx-b2c5ed169cbce41ed9e304ddcc13e841f465adb0.zip
Only render possible attributes for the given type.
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/worksheet/data_validation.rb27
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/axlsx/workbook/worksheet/data_validation.rb b/lib/axlsx/workbook/worksheet/data_validation.rb
index 908fdcf6..c2c1cb0e 100644
--- a/lib/axlsx/workbook/worksheet/data_validation.rb
+++ b/lib/axlsx/workbook/worksheet/data_validation.rb
@@ -181,7 +181,7 @@ module Axlsx
def error=(v); Axlsx::validate_string(v); @error = v end
# @see errorStyle
- def errorStyle=(v); Axlsx::validate_data_validation_errorStyle(v); @errorStyle = v end
+ def errorStyle=(v); Axlsx::validate_data_validation_error_style(v); @errorStyle = v end
# @see errorTitle
def errorTitle=(v); Axlsx::validate_string(v); @errorTitle = v end
@@ -214,12 +214,31 @@ module Axlsx
# @param [String] str
# @return [String]
def to_xml_string(str = '')
+ valid_attributes = get_valid_attributes
+
str << '<dataValidation '
- str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ')
+ str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' if (valid_attributes.include?(key.to_sym) and not CHILD_ELEMENTS.include?(key.to_sym)) }.join(' ')
str << '>'
- str << '<formula1>' << self.formula1 << '</formula1>' if @formula1
- str << '<formula2>' << self.formula2 << '</formula2>' if @formula2
+ str << '<formula1>' << self.formula1 << '</formula1>' if @formula1 and valid_attributes.include?(:formula1)
+ str << '<formula2>' << self.formula2 << '</formula2>' if @formula2 and valid_attributes.include?(:formula2)
str << '</dataValidation>'
end
+
+ private
+ def get_valid_attributes
+ attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type ]
+
+ if [:whole, :decimal, :data, :time, :textLength].include?(@type)
+ attributes << [:operator, :formula1, :formula2]
+ elsif @type == :list
+ attributes << [:showDropDown, :formula1]
+ elsif @type == :custom
+ attributes << :formula1
+ else
+ attributes = []
+ end
+
+ attributes.flatten!
+ end
end
end \ No newline at end of file