@@ -1249,3 +1249,91 @@ describe("Field", () => {
1249
1249
console . error . mockRestore ( ) ;
1250
1250
} ) ;
1251
1251
} ) ;
1252
+
1253
+ it ( "should support using format/parse with radio controls" , ( ) => {
1254
+ const format = ( value ) => value && value . toString ( ) ;
1255
+ const parse = ( value ) => value && parseInt ( value , 10 ) ;
1256
+
1257
+ const { getByTestId } = render (
1258
+ < Form onSubmit = { onSubmitMock } initialValues = { { number : 20 } } >
1259
+ { ( { handleSubmit } ) => (
1260
+ < form onSubmit = { handleSubmit } >
1261
+ < Field
1262
+ name = "number"
1263
+ component = "input"
1264
+ type = "radio"
1265
+ value = { 10 }
1266
+ data-testid = "ten"
1267
+ parse = { parse }
1268
+ format = { format }
1269
+ />
1270
+ < Field
1271
+ name = "number"
1272
+ component = "input"
1273
+ type = "radio"
1274
+ value = { 20 }
1275
+ data-testid = "twenty"
1276
+ parse = { parse }
1277
+ format = { format }
1278
+ />
1279
+ < Field
1280
+ name = "number"
1281
+ component = "input"
1282
+ type = "radio"
1283
+ value = { 30 }
1284
+ data-testid = "thirty"
1285
+ parse = { parse }
1286
+ format = { format }
1287
+ />
1288
+ </ form >
1289
+ ) }
1290
+ </ Form > ,
1291
+ ) ;
1292
+ expect ( getByTestId ( "ten" ) . checked ) . toBe ( false ) ;
1293
+ expect ( getByTestId ( "twenty" ) . checked ) . toBe ( true ) ;
1294
+ expect ( getByTestId ( "thirty" ) . checked ) . toBe ( false ) ;
1295
+ } ) ;
1296
+
1297
+ it ( "should support using format/parse with checkbox controls" , ( ) => {
1298
+ const format = ( value ) => value && value . map ( ( x ) => x . toString ( ) ) ;
1299
+ const parse = ( value ) => value && value . map ( ( x ) => parseInt ( x , 10 ) ) ;
1300
+
1301
+ const { getByTestId } = render (
1302
+ < Form onSubmit = { onSubmitMock } initialValues = { { number : [ 20 , 30 ] } } >
1303
+ { ( { handleSubmit } ) => (
1304
+ < form onSubmit = { handleSubmit } >
1305
+ < Field
1306
+ name = "number"
1307
+ component = "input"
1308
+ type = "checkbox"
1309
+ value = { 10 }
1310
+ data-testid = "ten"
1311
+ parse = { parse }
1312
+ format = { format }
1313
+ />
1314
+ < Field
1315
+ name = "number"
1316
+ component = "input"
1317
+ type = "checkbox"
1318
+ value = { 20 }
1319
+ data-testid = "twenty"
1320
+ parse = { parse }
1321
+ format = { format }
1322
+ />
1323
+ < Field
1324
+ name = "number"
1325
+ component = "input"
1326
+ type = "checkbox"
1327
+ value = { 30 }
1328
+ data-testid = "thirty"
1329
+ parse = { parse }
1330
+ format = { format }
1331
+ />
1332
+ </ form >
1333
+ ) }
1334
+ </ Form > ,
1335
+ ) ;
1336
+ expect ( getByTestId ( "ten" ) . checked ) . toBe ( false ) ;
1337
+ expect ( getByTestId ( "twenty" ) . checked ) . toBe ( true ) ;
1338
+ expect ( getByTestId ( "thirty" ) . checked ) . toBe ( true ) ;
1339
+ } ) ;
0 commit comments