diff --git a/readme.md b/readme.md index e23cfe6..a7dc3ee 100644 --- a/readme.md +++ b/readme.md @@ -111,10 +111,6 @@ as follows: **Formatted value** - `element.value` _(the normal input value)_ **Raw numeric value** - `element.rawValue` - -This function removes all the event listeners, making the input behaviour like the default browser -input once again. - API -------------------- diff --git a/src/helpers.js b/src/helpers.js index e535f6f..188193d 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -184,6 +184,7 @@ exports.allowedZero = function(val, char, caretPos, options) { */ exports.formattedToRaw = function(formattedValue, options) { if (is.not.string(formattedValue)) return NaN; + if (!formattedValue.length) return undefined; // Number(...) accepts thousands ',' or '' and decimal '.' so we must: diff --git a/test/unit/setRawValue.js b/test/unit/setRawValue.js index 34701e0..323e6ff 100644 --- a/test/unit/setRawValue.js +++ b/test/unit/setRawValue.js @@ -19,4 +19,17 @@ describe('setRawValue', () => { expect(element.value).toBe('0.00'); }); + it('has an initial value of empty string and rawValue of undefined', () => { + expect(element.value).toBe(''); + expect(element.rawValue).toBe(undefined); + }); + + it('resets back to empty string and undefined when entry is deleted', () => { + element.setRawValue(100); + element.setRawValue(''); + + expect(element.value).toBe(''); + expect(element.rawValue).toBe(undefined); + }); + });