Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add story for validator for cell editor
  • Loading branch information
AllenFang committed Sep 23, 2017
commit 79dd03b5f6d704a505f3a9a7c65d59c44bab55f8
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from 'react';
/* eslint no-unused-vars: 0 */
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';

const products = productsGenerator();

const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price',
validator: (newValue, row, column) => {
if (isNaN(newValue)) {
return {
valid: false,
message: 'Price should be numeric'
};
}
if (newValue < 2000) {
return {
valid: false,
message: 'Price should bigger than 2000'
};
}
return true;
}
}];

const sourceCode = `\
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price',
validator: (newValue, row, column) => {
if (isNaN(newValue)) {
return {
valid: false,
message: 'Price should be numeric'
};
}
if (newValue < 2000) {
return {
valid: false,
message: 'Price should bigger than 2000'
};
}
return true;
}
}];

const cellEdit = {
mode: 'click',
blurToSave: true
};

<BootstrapTableful
keyField='id'
data={ products }
columns={ columns }
cellEdit={ cellEdit }
/>
`;

const cellEdit = {
mode: 'click',
blurToSave: true
};
export default () => (
<div>
<h3>Product Price should bigger than $2000</h3>
<BootstrapTableful keyField="id" data={ products } columns={ columns } cellEdit={ cellEdit } />
<Code>{ sourceCode }</Code>
</div>
);
4 changes: 3 additions & 1 deletion packages/react-bootstrap-table2-example/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import BlurToSaveTable from 'examples/cell-edit/blur-to-save-table';
import RowLevelEditableTable from 'examples/cell-edit/row-level-editable-table';
import ColumnLevelEditableTable from 'examples/cell-edit/column-level-editable-table';
import CellEditHooks from 'examples/cell-edit/cell-edit-hooks-table';
import CellEditValidator from 'examples/cell-edit/cell-edit-validator-table';

// css style
import 'bootstrap/dist/css/bootstrap.min.css';
Expand Down Expand Up @@ -92,4 +93,5 @@ storiesOf('Cell Editing', module)
.add('Blur to Save Cell', () => <BlurToSaveTable />)
.add('Row Level Editable', () => <RowLevelEditableTable />)
.add('Column Level Editable', () => <ColumnLevelEditableTable />)
.add('Rich Hook Functions', () => <CellEditHooks />);
.add('Rich Hook Functions', () => <CellEditHooks />)
.add('Validation', () => <CellEditValidator />);