Skip to content

Commit fcd9e51

Browse files
miguel-snatanrolnik
authored andcommitted
Fix filter for negative and empty number input (#749)
* fix filter for negative and empty number input * fix formatting * add line to changelog
1 parent 186a6d5 commit fcd9e51

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### NEXT RELEASE
44

55
* _Contributing to this repo? Add info about your change here to be included in next release_
6+
* Fix: NaN displayed when filter input is empty or negative number (#749), thanks to [Miguel Serrrano](https://github.com/miguel-s)
67

78
### 1.1.0
89

src/components/BrowserFilter/FilterRow.react.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,22 @@ function compareValue(info, value, onChangeCompareTo, active) {
4949
case 'Boolean':
5050
return <ChromeDropdown color={active ? 'blue' : 'purple'} value={value ? 'True' : 'False'} options={['True', 'False']} onChange={(val) => onChangeCompareTo(val === 'True')} />;
5151
case 'Number':
52-
return <input type='text' value={value} onChange={(e) => onChangeCompareTo(validateNumeric(e.target.value) ? parseFloat(e.target.value) : (parseFloat(value) || ''))} />;
52+
return (
53+
<input
54+
type='text'
55+
value={value}
56+
onChange={(e) => {
57+
let val = value;
58+
if (!e.target.value.length) {
59+
val = '';
60+
} else if (e.target.value.length === 1) {
61+
val = validateNumeric(e.target.value) ? e.target.value : value;
62+
} else {
63+
val = validateNumeric(e.target.value) ? parseFloat(e.target.value) : value;
64+
}
65+
onChangeCompareTo(val);
66+
}} />
67+
);
5368
case 'Date':
5469
return (
5570
<DateTimeEntry

0 commit comments

Comments
 (0)