Skip to content

Commit

Permalink
fix #1391
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Jun 17, 2017
1 parent 92975d1 commit a2a5555
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
51 changes: 38 additions & 13 deletions src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,25 +828,50 @@ class BootstrapTable extends Component {
}

handleAddRow = newObj => {
let isAsync = false;
const { onAddRow } = this.props.options;

const afterHandleAddRow = errMsg => {
if (isAsync) {
this.refs.toolbar.afterHandleSaveBtnClick(errMsg);
} else {
return errMsg;
}
};

const afterAddRowCB = errMsg => {
if (typeof errMsg !== 'undefined' && errMsg !== '') return afterHandleAddRow(errMsg);
if (this.allowRemote(Const.REMOTE_INSERT_ROW)) {
if (this.props.options.afterInsertRow) {
this.props.options.afterInsertRow(newObj);
}
return afterHandleAddRow();
}

try {
this.store.add(newObj);
} catch (e) {
return afterHandleAddRow(e.message);
}
this._handleAfterAddingRow(newObj, false);
return afterHandleAddRow();
};

if (onAddRow) {
const colInfos = this.store.getColInfos();
onAddRow(newObj, colInfos);
}
const errMsg = onAddRow(newObj, colInfos, afterAddRowCB);

if (this.allowRemote(Const.REMOTE_INSERT_ROW)) {
if (this.props.options.afterInsertRow) {
this.props.options.afterInsertRow(newObj);
if (errMsg !== '' && errMsg !== false) {
return errMsg;
} else if (typeof errMsg === 'undefined') {
return afterAddRowCB();
} else {
isAsync = true;
return !isAsync;
}
return null;
}

try {
this.store.add(newObj);
} catch (e) {
return e.message;
} else {
return afterAddRowCB();
}
this._handleAfterAddingRow(newObj, false);
}

getSizePerPage() {
Expand Down
6 changes: 6 additions & 0 deletions src/toolbar/ToolBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ class ToolBar extends Component {
return;
}
const msg = this.props.onAddRow(newRow);
if (msg !== false) {
this.afterHandleSaveBtnClick(msg);
}
}

afterHandleSaveBtnClick = (msg) => {
if (msg) {
this.refs.notifier.notice('error', msg, 'Pressed ESC can cancel');
this.clearTimeout();
Expand Down

0 comments on commit a2a5555

Please sign in to comment.