Last active
February 13, 2017 15:03
-
-
Save AllenFang/f9c4a3056cd15a847b9af743680a2c05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // validator function pass the user input value and should return true|false. | |
| function jobNameValidator(value) { | |
| const response = { isValid: true, notification: { type: 'success', msg: '', title: '' } }; | |
| if (!value) { | |
| response.isValid = false; | |
| response.notification.type = 'error'; | |
| response.notification.msg = 'Value must be inserted'; | |
| response.notification.title = 'Requested Value'; | |
| } else if (value.length < 10) { | |
| response.isValid = false; | |
| response.notification.type = 'error'; | |
| response.notification.msg = 'Value must have 10+ characters'; | |
| response.notification.title = 'Invalid Value'; | |
| } | |
| return response; | |
| } | |
| function jobStatusValidator(value) { | |
| const nan = isNaN(parseInt(value, 10)); | |
| if (nan) { | |
| return 'Job Status must be a integer!'; | |
| } | |
| return true; | |
| } | |
| class DisableToastrTable extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| errType: '', | |
| errMsg: '' | |
| }; | |
| } | |
| render() { | |
| const options = { | |
| beforeShowError: (type, msg) => { | |
| this.setState({ | |
| errType: type, | |
| errMsg: msg | |
| }); | |
| // return false or do not return will not trigger the toastr, | |
| // if you want the toastr popup, you should return true always. | |
| } | |
| }; | |
| const cellEditProp = { | |
| mode: 'click', | |
| blurToSave: true | |
| }; | |
| return ( | |
| <div> | |
| <p style={ { color: 'red' } }>{ `[${this.state.errType}]: ${this.state.errMsg}` }</p> | |
| <BootstrapTable data={ jobs } cellEdit={ cellEditProp } options={ options }> | |
| <TableHeaderColumn dataField='id' isKey>Job ID</TableHeaderColumn> | |
| <TableHeaderColumn dataField='status' editable={ { validator: jobStatusValidator } }>Job Status</TableHeaderColumn> | |
| <TableHeaderColumn dataField='name' editable={ { type: 'textarea', validator: jobNameValidator } }>Job Name</TableHeaderColumn> | |
| <TableHeaderColumn dataField='type' editable={ { type: 'select', options: { values: jobTypes } } }>Job Type</TableHeaderColumn> | |
| <TableHeaderColumn dataField='active' editable={ { type: 'checkbox', options: { values: 'Y:N' } } }>Active</TableHeaderColumn> | |
| </BootstrapTable> | |
| </div> | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment