import './demo6.css'; import Button from '../../button'; import Checkbox from '../../checkbox'; import Field from '..'; import Input from '../../input'; import React from 'react'; import ReactDOM from 'react-dom'; const CheckboxGroup = Checkbox.Group; interface PageStates { checkboxStatus: boolean; } const list = [ { value: 'apple', label: 'apple', }, { value: 'pear', label: 'pear', }, { value: 'orange', label: 'orange', }, ]; class App extends React.Component<{}, PageStates> { field: Field; constructor(props) { super(props); this.state = { checkboxStatus: true, }; // @ts-ignore this.field = new Field(this, { scrollToFirstError: -10 }); } isChecked(rule, value, callback) { if (!value) { return callback('consent agreement not checked '); } return callback(); } userName(rule, value, callback) { if (value === 'frank') { setTimeout(() => callback('name existed'), 200); } else { setTimeout(() => callback(), 200); } } render() { const { init, validate, reset } = this.field; return (
{this.field.getError('input') ? ( {this.field.getError('input').join(',')} ) : ( '' )}

{this.field.getError('input1') ? ( {this.field.getError('input1').join(',')} ) : ( '' )}

{this.field.getState('username') === 'validating' ? 'validating...' : ''} {this.field.getError('username') ? ( {this.field.getError('username').join(',')} ) : ( '' )}

agreement: {/* @ts-ignore */} {this.field.getError('checkbox') ? ( {this.field.getError('checkbox').join(',')} ) : ( '' )}

{this.field.getError('textarea') ? ( {this.field.getError('textarea').join(',')} ) : ( '' )}

{this.state.checkboxStatus ? (
Array validate: {this.field.getError('checkboxgroup') ? ( {this.field.getError('checkboxgroup').join(',')} ) : ( '' )}
) : null}

); } } ReactDOM.render(, document.getElementById('field-demo-6'));