11import React , { useState , useRef } from 'react' ;
2- import { Form , Button , Toast , Slider , Flex , Text } from '@uiw/react-native' ;
2+ import { Form , Button , Toast , Slider , Flex , Text , Spacing } from '@uiw/react-native' ;
33import { View } from 'react-native' ;
44import Layout , { Container } from '../../Layout' ;
55const { Body, Footer, Card} = Layout ;
@@ -18,6 +18,42 @@ const FormDemo = () => {
1818 const [ state , setStore ] = useState ( { } ) ;
1919
2020 const schema = [
21+ {
22+ type : 'input' ,
23+ field : 'name' ,
24+ name : '姓名' ,
25+ attr : { } ,
26+ required : true ,
27+ validate : ( val : any ) => ( ! val ? `请输入name` : '' ) ,
28+ } ,
29+ {
30+ type : 'input' ,
31+ field : 'phone' ,
32+ name : '电话' ,
33+ attr : { } ,
34+ required : true ,
35+ validate : ( val : any ) => ( ! val ? `请输入电话` : '' ) ,
36+ } ,
37+ {
38+ type : 'radio' ,
39+ field : 'sex' ,
40+ name : '单选框' ,
41+ options : [
42+ { label : '四川菜' , value : 1 } ,
43+ { label : '湖北菜' , value : 2 } ,
44+ { label : '西北菜' , value : 3 } ,
45+ { label : '新疆菜' , value : 4 } ,
46+ { label : '东北菜' , value : 5 } ,
47+ { label : '四川菜' , value : 6 } ,
48+ { label : '湖北菜' , value : 7 } ,
49+ { label : '西北菜' , value : 8 } ,
50+ { label : '新疆菜' , value : 9 } ,
51+ { label : '东北菜' , value : 10 } ,
52+ ] ,
53+ } ,
54+ ] ;
55+
56+ const schemaCard = [
2157 {
2258 type : 'input' ,
2359 field : 'name' ,
@@ -60,6 +96,58 @@ const FormDemo = () => {
6096 { label : '东北菜' , value : 10 } ,
6197 ] ,
6298 } ,
99+ ] ;
100+ const schemaType = [
101+ {
102+ type : 'input' ,
103+ field : 'name' ,
104+ name : '姓名' ,
105+ attr : { } ,
106+ required : true ,
107+ validate : ( val : any ) => ( ! val ? `请输入name` : '' ) ,
108+ } ,
109+ {
110+ type : 'input' ,
111+ field : 'phone' ,
112+ name : '电话' ,
113+ attr : { } ,
114+ required : true ,
115+ validate : ( val : any ) => ( ! val ? `请输入电话` : '' ) ,
116+ } ,
117+ {
118+ type : 'radio' ,
119+ field : 'sex' ,
120+ name : '单选框' ,
121+ options : [
122+ { label : '四川菜' , value : 1 } ,
123+ { label : '湖北菜' , value : 2 } ,
124+ { label : '西北菜' , value : 3 } ,
125+ { label : '新疆菜' , value : 4 } ,
126+ { label : '东北菜' , value : 5 } ,
127+ { label : '四川菜' , value : 6 } ,
128+ { label : '湖北菜' , value : 7 } ,
129+ { label : '西北菜' , value : 8 } ,
130+ { label : '新疆菜' , value : 9 } ,
131+ { label : '东北菜' , value : 10 } ,
132+ ] ,
133+ } ,
134+ {
135+ type : 'checkBox' ,
136+ field : 'fruit' ,
137+ name : '多选框' ,
138+ options : [
139+ { label : '香蕉' , value : 1 } ,
140+ { label : '西瓜' , value : 2 } ,
141+ { label : '猕猴桃' , value : 3 } ,
142+ { label : '新疆菜' , value : 4 } ,
143+ { label : '东北菜' , value : 5 } ,
144+ { label : '四川菜' , value : 6 } ,
145+ { label : '湖北菜' , value : 7 } ,
146+ { label : '西北菜' , value : 8 } ,
147+ { label : '新疆菜' , value : 9 } ,
148+ { label : '东北菜' , value : 10 } ,
149+ ] ,
150+ } ,
63151 {
64152 type : 'rate' ,
65153 field : 'rate' ,
@@ -232,7 +320,57 @@ const FormDemo = () => {
232320 < Form
233321 form = { form }
234322 schema = { schema }
235- initialValues = { { name : '王滴滴' , rate : 4 , datePicker : new Date ( ) , picker : [ '2' ] } }
323+ initialValues = { { name : '王滴滴' } }
324+ watch = { {
325+ name : ( value : unknown ) => console . log ( 'value' , value ) ,
326+ } }
327+ customComponentList = { {
328+ render : < Slider /> ,
329+ } }
330+ changeValidate = { true }
331+ />
332+ < Button
333+ type = "primary"
334+ onPress = { ( ) => {
335+ form
336+ . validateFields ( )
337+ . then ( ( values : any ) => setStore ( values ) )
338+ . catch ( ( errors : any ) => Toast . warning ( JSON . stringify ( errors ) ) ) ;
339+ } } >
340+ 确定
341+ </ Button >
342+ </ Card >
343+ < Card title = "卡片模式" >
344+ < Form
345+ form = { form }
346+ schema = { schemaCard }
347+ mode = "card"
348+ initialValues = { { name : '王滴滴' , rate : 4 } }
349+ watch = { {
350+ name : ( value : unknown ) => console . log ( 'value' , value ) ,
351+ } }
352+ customComponentList = { {
353+ render : < Slider /> ,
354+ } }
355+ changeValidate = { true }
356+ />
357+ < Spacing />
358+ < Button
359+ type = "primary"
360+ onPress = { ( ) => {
361+ form
362+ . validateFields ( )
363+ . then ( ( values : any ) => setStore ( values ) )
364+ . catch ( ( errors : any ) => Toast . warning ( JSON . stringify ( errors ) ) ) ;
365+ } } >
366+ 确定
367+ </ Button >
368+ </ Card >
369+ < Card title = "表单项类型" >
370+ < Form
371+ form = { form }
372+ schema = { schemaType }
373+ initialValues = { { name : '王滴滴' , rate : 4 } }
236374 watch = { {
237375 name : ( value : unknown ) => console . log ( 'value' , value ) ,
238376 } }
@@ -241,9 +379,11 @@ const FormDemo = () => {
241379 } }
242380 changeValidate = { true }
243381 />
382+ < Spacing />
244383 < View >
245384 < Text color = "primary_text" > { JSON . stringify ( state ) } </ Text >
246385 </ View >
386+ < Spacing />
247387 < Button
248388 type = "primary"
249389 onPress = { ( ) => {
@@ -254,12 +394,15 @@ const FormDemo = () => {
254394 } } >
255395 确定
256396 </ Button >
397+ < Spacing />
257398 < Button type = "primary" onPress = { ( ) => form . setFieldValue ( 'age' , '456' ) } >
258399 设置
259400 </ Button >
401+ < Spacing />
260402 < Button type = "primary" onPress = { ( ) => form . resetFieldValue ( ) } >
261403 重置
262404 </ Button >
405+ < Spacing />
263406 < Button
264407 type = "primary"
265408 onPress = { ( ) => {
0 commit comments