Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset value to '' and rawValue to undefined when input is cleared #129

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------

Expand Down
1 change: 1 addition & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
13 changes: 13 additions & 0 deletions test/unit/setRawValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

});