/* eslint-disable */ import React, { Component } from 'react'; import { Button, Row, Col, InputGroup as BasicInputGroup, AutoComplete } from '../../index'; import { Form, useFormState, ArrayField, withField } from '../index'; import BasicSelect from '../../select/index'; import BasicInput from '../../input/index'; import BasicInputNumber from '../../inputNumber/index'; import LocaleProvider from '../../locale/localeProvider'; import zh_CN from '@douyinfe/semi-ui/locale/source/zh_CN'; import en_GB from '@douyinfe/semi-ui/locale/source/en_GB'; import en_US from '@douyinfe/semi-ui/locale/source/en_US'; import ko_KR from '@douyinfe/semi-ui/locale/source/ko_KR'; import ja_JP from '@douyinfe/semi-ui/locale/source/ja_JP'; import { UseFormApiDemo, UseFormStateDemo, UseFieldApiDemo, UseFieldStateDemo, WithFormStateDemo, WithFormApiDemo, ComponentUsingFormState, CustomStringify, } from './Hook/hookDemo'; const { Input, Select, DatePicker, Switch, Slider, CheckboxGroup, Checkbox, RadioGroup, Radio, TimePicker, InputNumber, InputGroup } = Form; const plainOptions = ['Apple', 'Pear', 'Orange']; const treeData = [ { label: '亚洲', value: 'Asia', key: '0', children: [ { label: '中国', value: 'China', key: '0-0', children: [ { label: '北京', value: 'Beijing', key: '0-0-0', }, { label: '上海', value: 'Shanghai', key: '0-0-1', }, ], }, ], }, { label: '北美洲', value: 'North America', key: '1', } ]; const DifferentDeclareUsage = () => (

一般写法

以下的几种写法可以直接在Form结构内部获取到formState值

通过Render Props

( <> {CustomStringify(formState)} )} layout="horizontal" >

通过child render function

{({ formState }) => ( <> {CustomStringify(formState)} )}

通过props.component

{/*
*/}

通过withFormState Hoc(示例见Hoc部分)

通过useFormState Hooks(示例见Hooks部分)

) class BasicDemoWithInit extends Component { constructor() { super(); this.state = { filed: {}, layout: 'vertical', // layout: 'horizontal', labelPosition: 'left', // labelPosition: 'top', labelAlign: 'left' // horizontal }; this.getFormApi = this.getFormApi.bind(this); this.changeLayout = this.changeLayout.bind(this); this.changeLabelPos = this.changeLabelPos.bind(this); this.changeLabelAlign = this.changeLabelAlign.bind(this); this.handleReset = this.handleReset.bind(this); this.validate = this.validate.bind(this); } changeLayout(layout) { this.setState({ layout }); } changeLabelPos(labelPosition) { this.setState({ labelPosition }); } changeInput() { this.formApi.setValue('input', Math.random()); } changeLabelAlign(labelAlign) { this.setState({ labelAlign }); } changeSelect() { this.formApi.setValue('select', 'jane'); } getFormApi(formApi) { this.formApi = formApi; } handleReset() { console.log('reset') } validate() { this.formApi.validate() .then(value => { debugger }) .catch(error => { debugger }) } render() { const { layout, labelPosition, labelAlign } = this.state; const formInitValue = { // name: 'semi', business: ['hotsoon'], role: 'ued', tree: 'Beijing' }; const plainOptions = ['A', 'B', 'C']; const style = { width: '90%' }; return ( <>
vertical horizontal top left inset left right
console.log(v)} style={{ padding: '10px', width: 900 }} autoScrollToError aria-label='Demo Form' id='demo-form-id' > value === 'muji', message: 'not muji' } ]} /> 运营 开发 产品 设计 抖音 火山小视频 今日头条 管理员admin 用户user 访客guest 根用户root 单选框标题 单选框标题 即时推送 定时推送 动态推送 我已阅读并清楚相关规定
); } } class LinkFieldForm extends Component { constructor() { super(); this.state = { filed: {}, }; this.getFormApi = this.getFormApi.bind(this); this.handleSelectChange = this.handleSelectChange.bind(this); } handleSelectChange(value) { let text = value === 'male' ? 'Hi male' : 'Hi female!'; // this.formApi.setValue('Note', text); } getFormApi(formApi) { this.formApi = formApi; } render() { return (
Note will change after Sex select
); } } export { BasicDemoWithInit, LinkFieldForm, DifferentDeclareUsage };