8
8
Form ,
9
9
useFormState ,
10
10
} from 'react-native-use-form' ;
11
- import { Appbar , Button , Surface , Text , Title } from 'react-native-paper' ;
11
+ import { Appbar , Button , Text } from 'react-native-paper' ;
12
12
import TextInputWithError from './TextInputWithError' ;
13
13
import { useRef } from 'react' ;
14
14
import { SafeAreaProvider } from 'react-native-safe-area-context' ;
@@ -30,7 +30,9 @@ type FormType = {
30
30
password : string ;
31
31
age : number | undefined ;
32
32
money : number | undefined ;
33
+ description : string | undefined ;
33
34
postalCode : string | undefined ;
35
+ postalCodeDisabled : string | undefined ;
34
36
organization : {
35
37
name : string ;
36
38
telephone : string ;
@@ -52,9 +54,11 @@ export default function App() {
52
54
email : '' ,
53
55
telephone : '' ,
54
56
password : '' ,
55
- age : 0 ,
56
- money : 0 ,
57
+ age : undefined ,
58
+ money : undefined ,
59
+ description : '' ,
57
60
postalCode : '' ,
61
+ postalCodeDisabled : '' ,
58
62
organization : {
59
63
name : '' ,
60
64
telephone : '' ,
@@ -135,6 +139,16 @@ export default function App() {
135
139
label : 'Postalcode' ,
136
140
} ) }
137
141
/>
142
+ < TextInputWithError
143
+ editable = { false }
144
+ mode = "outlined"
145
+ { ...fh . text ( 'postalCode' , {
146
+ enhance : ( v ) => {
147
+ return ( v || '' ) . toUpperCase ( ) ;
148
+ } ,
149
+ label : 'Postalcode (disabled)' ,
150
+ } ) }
151
+ />
138
152
139
153
< TextInputWithError
140
154
mode = "outlined"
@@ -189,8 +203,17 @@ export default function App() {
189
203
label : 'Organization revenue' ,
190
204
} ) }
191
205
/>
192
- < AddressEdit { ...fh . raw ( 'address' ) } />
193
- < AddressCompanyEdit { ...fh . raw ( 'address.company' ) } />
206
+ < TextInputWithError
207
+ mode = "outlined"
208
+ { ...fh . text ( 'description' , {
209
+ label : 'Description' ,
210
+ required : true ,
211
+ minLength : 3 ,
212
+ maxLength : 10 ,
213
+ } ) }
214
+ />
215
+ { /*<AddressEdit {...fh.raw('address')} />*/ }
216
+ { /*<AddressCompanyEdit {...fh.raw('address.company')} />*/ }
194
217
< Button
195
218
mode = "contained"
196
219
onPress = { submit }
@@ -206,66 +229,66 @@ export default function App() {
206
229
) ;
207
230
}
208
231
209
- function AddressEdit ( {
210
- value,
211
- onChange,
212
- ...rest
213
- } : {
214
- value : AddressType | null | undefined ;
215
- onChange : ( v : AddressType | null | undefined ) => void ;
216
- } ) {
217
- const [ { formProps } , fh ] = useFormState < AddressType > (
218
- value || { street : '' , houseNumber : '' , company : { name : '' } } ,
219
- {
220
- onChange,
221
- }
222
- ) ;
223
- return (
224
- < Surface { ...rest } >
225
- < Title > Nested form</ Title >
226
- < Form { ...formProps } >
227
- < TextInputWithError
228
- mode = "outlined"
229
- label = "Street"
230
- { ...fh . streetAddress ( 'street' , { required : true } ) }
231
- />
232
- < TextInputWithError
233
- mode = "outlined"
234
- label = "House number"
235
- { ...fh . streetAddress ( 'houseNumber' ) }
236
- />
237
- </ Form >
238
- </ Surface >
239
- ) ;
240
- }
241
-
242
- function AddressCompanyEdit ( {
243
- value,
244
- onChange,
245
- ...rest
246
- } : {
247
- value : AddressCompany | undefined | null ;
248
- onChange : ( v : AddressCompany | undefined | null ) => void ;
249
- } ) {
250
- const [ { formProps } , fh ] = useFormState < AddressCompany > (
251
- value || { name : '' } ,
252
- {
253
- onChange,
254
- }
255
- ) ;
256
- return (
257
- < Surface { ...rest } style = { { padding : 12 } } >
258
- < Title > Nested form</ Title >
259
- < Form { ...formProps } >
260
- < TextInputWithError
261
- mode = "outlined"
262
- label = "Street"
263
- { ...fh . text ( 'name' ) }
264
- />
265
- </ Form >
266
- </ Surface >
267
- ) ;
268
- }
232
+ // function AddressEdit({
233
+ // value,
234
+ // onChange,
235
+ // ...rest
236
+ // }: {
237
+ // value: AddressType | null | undefined;
238
+ // onChange: (v: AddressType | null | undefined) => void;
239
+ // }) {
240
+ // const [{ formProps }, fh] = useFormState<AddressType>(
241
+ // value || { street: '', houseNumber: '', company: { name: '' } },
242
+ // {
243
+ // onChange,
244
+ // }
245
+ // );
246
+ // return (
247
+ // <Surface {...rest}>
248
+ // <Title>Nested form</Title>
249
+ // <Form {...formProps}>
250
+ // <TextInputWithError
251
+ // mode="outlined"
252
+ // label="Street"
253
+ // {...fh.streetAddress('street', { required: true }) }
254
+ // />
255
+ // <TextInputWithError
256
+ // mode="outlined"
257
+ // label="House number"
258
+ // {...fh.streetAddress('houseNumber')}
259
+ // />
260
+ // </Form>
261
+ // </Surface>
262
+ // );
263
+ // }
264
+ //
265
+ // function AddressCompanyEdit({
266
+ // value,
267
+ // onChange,
268
+ // ...rest
269
+ // }: {
270
+ // value: AddressCompany | undefined | null;
271
+ // onChange: (v: AddressCompany | undefined | null) => void;
272
+ // }) {
273
+ // const [{ formProps }, fh] = useFormState<AddressCompany>(
274
+ // value || { name: '' },
275
+ // {
276
+ // onChange,
277
+ // }
278
+ // );
279
+ // return (
280
+ // <Surface {...rest} style={{ padding: 12 }}>
281
+ // <Title>Nested form</Title>
282
+ // <Form {...formProps}>
283
+ // <TextInputWithError
284
+ // mode="outlined"
285
+ // label="Street"
286
+ // {...fh.text('name')}
287
+ // />
288
+ // </Form>
289
+ // </Surface>
290
+ // );
291
+ // }
269
292
270
293
const telephoneRegex = {
271
294
regex : new RegExp ( / ^ \d + $ / ) ,
0 commit comments