Skip to content

Commit f80af3e

Browse files
committed
Merge branch 'fix-double-validation' of https://github.com/jspaine/react-bootstrap-table into jspaine-fix-double-validation
2 parents b06fd5b + 5532b98 commit f80af3e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/TableEditColumn.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ class TableEditColumn extends Component {
2424

2525
handleKeyPress = e => {
2626
if (e.keyCode === 13 || e.keyCode === 9) {
27-
// Pressed ENTER
27+
// Pressed ENTER or TAB
2828
const value = e.currentTarget.type === 'checkbox' ?
2929
this._getCheckBoxValue(e) : e.currentTarget.value;
3030

31-
if (!this.validator(value)) {
31+
// TAB triggers blur so no need to notify
32+
const notify = e.keyCode !== 9 || !this.props.blurToSave;
33+
if (!this.validator(value, notify)) {
3234
return;
3335
}
36+
3437
if (e.keyCode === 13) {
3538
this.props.completeEdit(value, this.props.rowIndex, this.props.colIndex);
3639
} else {
@@ -72,18 +75,18 @@ class TableEditColumn extends Component {
7275

7376
// modified by iuculanop
7477
// BEGIN
75-
validator(value) {
78+
validator(value, notify = true) {
7679
const ts = this;
7780
let valid = true;
7881
if (ts.props.editable.validator) {
7982
const checkVal = ts.props.editable.validator(value, this.props.row);
8083
const responseType = typeof checkVal;
8184
if (responseType !== 'object' && checkVal !== true) {
8285
valid = false;
83-
this.notifyToastr('error', checkVal, '');
86+
notify && this.notifyToastr('error', checkVal, '');
8487
} else if (responseType === 'object' && checkVal.isValid !== true) {
8588
valid = false;
86-
this.notifyToastr(checkVal.notification.type,
89+
notify && this.notifyToastr(checkVal.notification.type,
8790
checkVal.notification.msg,
8891
checkVal.notification.title);
8992
}

0 commit comments

Comments
 (0)