Skip to content

Commit

Permalink
Prevent tab default behaviour if validate invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
NellyHaglund committed Oct 1, 2019
1 parent 9cbcca8 commit 8f4e088
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/datatable/BodyCell.js
Expand Up @@ -30,7 +30,7 @@ export class BodyCell extends Component {

onKeyDown(event) {
if (event.which === 13 || event.which === 9) { // tab || enter
this.switchCellToViewMode(true);
this.switchCellToViewMode(true, event);
}
if (event.which === 27) // escape
{
Expand All @@ -52,9 +52,9 @@ export class BodyCell extends Component {
}
}

onBlur() {
onBlur(event) {
if (this.state.editing && this.props.editorValidatorEvent === 'blur') {
this.switchCellToViewMode(true);
this.switchCellToViewMode(true, event);
}
}

Expand All @@ -66,7 +66,7 @@ export class BodyCell extends Component {
if (!this.documentEditListener) {
this.documentEditListener = (event) => {
if (!this.editingCellClick) {
this.switchCellToViewMode(true);
this.switchCellToViewMode(true, event);
}

this.editingCellClick = false;
Expand All @@ -86,7 +86,7 @@ export class BodyCell extends Component {
this.unbindDocumentEditListener();
}

switchCellToViewMode(submit) {
switchCellToViewMode(submit, event = {}) {
if (this.props.editorValidator && submit) {
let valid = this.props.editorValidator(this.props);
if (valid) {
Expand All @@ -95,6 +95,9 @@ export class BodyCell extends Component {
}
this.closeCell();
} // as per previous version if not valid and another editor is open, keep invalid data editor open.
else {
event.preventDefault();
}
}
else {
if (submit && this.props.onEditorSubmit) {
Expand Down

0 comments on commit 8f4e088

Please sign in to comment.