Skip to content

Commit

Permalink
fix double validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
jspaine committed Jul 13, 2017
1 parent 3017388 commit ab96032
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/TableEditColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ class TableEditColumn extends Component {

handleKeyPress = e => {
if (e.keyCode === 13 || e.keyCode === 9) {
// Pressed ENTER
// Pressed ENTER or TAB
const value = e.currentTarget.type === 'checkbox' ?
this._getCheckBoxValue(e) : e.currentTarget.value;

if (!this.validator(value)) {
// TAB triggers blur so no need to notify
const notify = e.keyCode !== 9;
if (!this.validator(value, notify)) {
return;
}

if (e.keyCode === 13) {
this.props.completeEdit(value, this.props.rowIndex, this.props.colIndex);
} else {
Expand Down Expand Up @@ -72,18 +75,18 @@ class TableEditColumn extends Component {

// modified by iuculanop
// BEGIN
validator(value) {
validator(value, notify = true) {
const ts = this;
let valid = true;
if (ts.props.editable.validator) {
const checkVal = ts.props.editable.validator(value, this.props.row);
const responseType = typeof checkVal;
if (responseType !== 'object' && checkVal !== true) {
valid = false;
this.notifyToastr('error', checkVal, '');
notify && this.notifyToastr('error', checkVal, '');
} else if (responseType === 'object' && checkVal.isValid !== true) {
valid = false;
this.notifyToastr(checkVal.notification.type,
notify && this.notifyToastr(checkVal.notification.type,
checkVal.notification.msg,
checkVal.notification.title);
}
Expand Down

0 comments on commit ab96032

Please sign in to comment.