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' ,
@@ -275,7 +363,57 @@ const FormDemo = () => {
275363 < Form
276364 form = { form }
277365 schema = { schema }
278- initialValues = { { name : '王滴滴' , rate : 4 , datePicker : new Date ( ) , picker : [ '2' ] } }
366+ initialValues = { { name : '王滴滴' } }
367+ watch = { {
368+ name : ( value : unknown ) => console . log ( 'value' , value ) ,
369+ } }
370+ customComponentList = { {
371+ render : < Slider /> ,
372+ } }
373+ changeValidate = { true }
374+ />
375+ < Button
376+ type = "primary"
377+ onPress = { ( ) => {
378+ form
379+ . validateFields ( )
380+ . then ( ( values : any ) => setStore ( values ) )
381+ . catch ( ( errors : any ) => Toast . warning ( JSON . stringify ( errors ) ) ) ;
382+ } } >
383+ 确定
384+ </ Button >
385+ </ Card >
386+ < Card title = "卡片模式" >
387+ < Form
388+ form = { form }
389+ schema = { schemaCard }
390+ mode = "card"
391+ initialValues = { { name : '王滴滴' , rate : 4 } }
392+ watch = { {
393+ name : ( value : unknown ) => console . log ( 'value' , value ) ,
394+ } }
395+ customComponentList = { {
396+ render : < Slider /> ,
397+ } }
398+ changeValidate = { true }
399+ />
400+ < Spacing />
401+ < Button
402+ type = "primary"
403+ onPress = { ( ) => {
404+ form
405+ . validateFields ( )
406+ . then ( ( values : any ) => setStore ( values ) )
407+ . catch ( ( errors : any ) => Toast . warning ( JSON . stringify ( errors ) ) ) ;
408+ } } >
409+ 确定
410+ </ Button >
411+ </ Card >
412+ < Card title = "表单项类型" >
413+ < Form
414+ form = { form }
415+ schema = { schemaType }
416+ initialValues = { { name : '王滴滴' , rate : 4 } }
279417 watch = { {
280418 name : ( value : unknown ) => console . log ( 'value' , value ) ,
281419 } }
@@ -284,9 +422,11 @@ const FormDemo = () => {
284422 } }
285423 changeValidate = { true }
286424 />
425+ < Spacing />
287426 < View >
288427 < Text color = "primary_text" > { JSON . stringify ( state ) } </ Text >
289428 </ View >
429+ < Spacing />
290430 < Button
291431 type = "primary"
292432 onPress = { ( ) => {
@@ -297,12 +437,15 @@ const FormDemo = () => {
297437 } } >
298438 确定
299439 </ Button >
440+ < Spacing />
300441 < Button type = "primary" onPress = { ( ) => form . setFieldValue ( 'age' , '456' ) } >
301442 设置
302443 </ Button >
444+ < Spacing />
303445 < Button type = "primary" onPress = { ( ) => form . resetFieldValue ( ) } >
304446 重置
305447 </ Button >
448+ < Spacing />
306449 < Button
307450 type = "primary"
308451 onPress = { ( ) => {
0 commit comments