Skip to content

Commit

Permalink
Fixed #652
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yadav committed Oct 25, 2022
1 parent 5a4d4f0 commit c4f3935
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/pattern_format.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function removeFormatting<BaseType = InputAttributes>(
const removeFormatChar = (string: string, startIndex: number) => {
let str = '';
for (let i = 0; i < string.length; i++) {
if (isNumericSlot(startIndex + i)) {
if (isNumericSlot(startIndex + i) && string[i].match(/\d/)) {
str += string[i];
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/library/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,19 @@ describe('NumberFormat as input', () => {
simulateKeyInput(wrapper.find('input'), '8', 0, format.length);
expect(getInputValue(wrapper)).toEqual('+1 (8__) ___ _ __ US');
});

it('should give proper value when format character has number #652', () => {
//https://github.com/s-yadav/react-number-format/issues/652#issuecomment-1278200770
const spy = jasmine.createSpy();
const wrapper = mount(<PatternFormat format="13###" mask="_" onValueChange={spy} />);
simulateKeyInput(wrapper.find('input'), '3', 0);
simulateKeyInput(wrapper.find('input'), '4', 3);
expect(spy.calls.argsFor(1)[0]).toEqual({
formattedValue: '1334_',
value: '34',
floatValue: 34,
});
})

it('should not allow replacing all characters with number when formatting is present for NumericFormats', () => {
//check for numeric input
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
entry: {
bundle: ['./example/src/index.js'],
},
devtool: 'eval',
devtool: 'eval-source-map',
output: {
filename: '[name].js',
},
Expand Down

0 comments on commit c4f3935

Please sign in to comment.