From 536beb0d40243c76026cbd74828fcdb09e49652b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 30 Apr 2013 23:10:22 -0700 Subject: [PATCH] Support setting number fields to 0 Previously entering 0 would end up as '0' in the config value instead of as a numeric value. --- spec/app/config-panel-spec.coffee | 12 ++++++++++++ src/app/config-panel.coffee | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/spec/app/config-panel-spec.coffee b/spec/app/config-panel-spec.coffee index 0b56292b7..e79571c7d 100644 --- a/spec/app/config-panel-spec.coffee +++ b/spec/app/config-panel-spec.coffee @@ -39,6 +39,12 @@ describe "ConfigPanel", -> panel.floatInput.val('90.2').change() expect(config.get('foo.float')).toBe 90.2 + panel.intInput.val('0').change() + expect(config.get('foo.int')).toBe 0 + + panel.floatInput.val('0').change() + expect(config.get('foo.float')).toBe 0 + panel.stringInput.val('moo').change() expect(config.get('foo.string')).toBe 'moo' @@ -102,6 +108,12 @@ describe "ConfigPanel", -> expect(config.get('foo.float')).toBe undefined expect(config.get('foo.string')).toBe undefined + panel.intEditor.setText('0') + panel.floatEditor.setText('0') + window.advanceClock(10000) # wait for contents-modified to be triggered + expect(config.get('foo.int')).toBe 0 + expect(config.get('foo.float')).toBe 0 + it "does not save the config value until it has been changed to a new value", -> class TestPanel extends ConfigPanel @content: -> diff --git a/src/app/config-panel.coffee b/src/app/config-panel.coffee index 663aa5697..e0dcb811b 100644 --- a/src/app/config-panel.coffee +++ b/src/app/config-panel.coffee @@ -32,8 +32,12 @@ class ConfigPanel extends View parseValue: (type, value) -> switch type - when 'int' then value = parseInt(value) or value - when 'float' then value = parseFloat(value) or value + when 'int' + intValue = parseInt(value) + value = intValue unless isNaN(intValue) + when 'float' + floatValue = parseFloat(value) + value = floatValue unless isNaN(floatValue) value = undefined if value == '' value