@@ -37,9 +37,7 @@ import { SafeAreaView,Toast } from 'react-native';
3737import { Form } from ' @uiw/react-native' ;
3838
3939const FormDemo = () => {
40- const form = Form .useForm ({
41- changeValidate: true ,
42- });
40+ const form = Form .useForm ();
4341 const initialValues = {name: ' ' };
4442 const items = [
4543 {
@@ -78,12 +76,10 @@ import { SafeAreaView,Toast,Slider } from 'react-native';
7876import { Form } from ' @uiw/react-native' ;
7977
8078const FormDemo = () => {
81- const form = Form .useForm ({
82- changeValidate: true ,
83- customComponentList: {
79+ const form = Form .useForm ();
80+ const customComponentList = {
8481 render: < Slider / > ,
85- },
86- });
82+ }
8783 const initialValues = {name: ' ' };
8884 const items = [
8985 {
@@ -100,7 +96,7 @@ const FormDemo = () => {
10096 ];
10197 return (
10298 < SafeAreaView>
103- < Form form= {form} schema= {items} initialValues= {initialValues} / >
99+ < Form form= {form} schema= {items} changeValidate = { true } customComponentList = {customComponentList} initialValues= {initialValues} / >
104100 < / SafeAreaView>
105101 );
106102};
@@ -115,14 +111,10 @@ import { SafeAreaView,Toast } from 'react-native';
115111import { Form } from ' @uiw/react-native' ;
116112
117113const FormDemo = () => {
118- const form = Form .useForm ({
119- changeValidate: true ,
120- watch: {
121- name : (value : unknown ) => {
122- console .log (' value' , value);
123- },
124- }
125- });
114+ const form = Form .useForm ();
115+ const watch = {
116+ name : (value ) => console .log (' value' , value)
117+ }
126118 const initialValues = {name: ' ' };
127119 const items = [
128120 {
@@ -134,7 +126,7 @@ const FormDemo = () => {
134126 ];
135127 return (
136128 < SafeAreaView>
137- < Form form= {form} schema= {items} initialValues= {initialValues} / >
129+ < Form form= {form} schema= {items} watch = {watch} initialValues= {initialValues} / >
138130 < / SafeAreaView>
139131 );
140132};
@@ -154,9 +146,7 @@ import { SafeAreaView,View,Text } from 'react-native';
154146import { Form ,Button ,Flex } from ' @uiw/react-native' ;
155147
156148const FormDemo = () => {
157- const form = Form .useForm ({
158- changeValidate: true ,
159- });
149+ const form = Form .useForm ();
160150 const initialValues = {name: ' ' };
161151 const items = [
162152 {
@@ -177,7 +167,7 @@ const FormDemo = () => {
177167 < / Flex>
178168 < / View>
179169 ),
180- renderAdd: ({add} : { add : () => void }) => (
170+ renderAdd : ({ add }) => (
181171 < View style= {{marginTop: 12 }}>
182172 < Button onPress= {() => add ()} type= " primary" size= " default" bordered= {false }>
183173 新增数据
@@ -225,7 +215,13 @@ interface FormProps<FormData = any, FieldValue = FormData[keyof FormData], Field
225215 /**
226216 * 支持默认和卡片两种模式
227217 */
228- mode? : ' default' | ' card'
218+ mode? : ' default' | ' card' ;
219+ // 表单是否在onChange时进行验证
220+ changeValidate? : boolean ;
221+ // 监听表单字段变化
222+ watch? : Partial <Record <string , (value : unknown ) => void >>;
223+ // 自定义组件
224+ customComponentList? : Partial <Record <string , JSX .Element >>;
229225}
230226```
231227
@@ -240,7 +236,7 @@ interface FormItemsProps {
240236 name: string ;
241237 // 验证规则
242238 validate? : RulesOption [' validate' ];
243- options? : Array <{ label: string ; value: KeyType | any }>;
239+ options? : Array <{ label: string ; value: KeyType }>;
244240 // 表单控件props
245241 attr? : any ;
246242 // 展示是否必填
@@ -283,3 +279,5 @@ type FormInstance<FormData = any, FieldValue = FormData[keyof FormData], FieldKe
283279};
284280```
285281
282+
283+
0 commit comments