@@ -20,15 +20,15 @@ import FormGroup from "@oxygen-ui/react/FormGroup";
2020import { IdentifiableComponentInterface , TestableComponentInterface } from "@wso2is/core/models" ;
2121import { Hint } from "@wso2is/react-components" ;
2222import { FieldState } from "final-form" ;
23- import React , { ReactElement , ReactNode } from "react" ;
23+ import React , { FunctionComponent , ReactElement , ReactNode } from "react" ;
2424import { FieldProps , FieldRenderProps , Field as FinalFormField } from "react-final-form" ;
2525import SelectFieldAdapter from "../../../components/adapters/select-field-adapter" ;
2626import { getValidation } from "../utils/validate" ;
2727
2828/**
2929 * Option of a dynamic select field.
3030 */
31- export interface DynamicFieldOptionInterface {
31+ interface DynamicFieldOptionInterface {
3232 /**
3333 * Text displayed for the option.
3434 */
@@ -39,7 +39,13 @@ export interface DynamicFieldOptionInterface {
3939 value : string ;
4040}
4141
42- export interface FieldSelectPropsInterface extends Omit < FieldProps < any , any , any > , "component" > ,
42+ /**
43+ * Value a dynamic select field holds. Multiple selection is not supported.
44+ */
45+ type DynamicSelectFieldValueType = string ;
46+
47+ interface FieldSelectPropsInterface
48+ extends Omit < FieldProps < DynamicSelectFieldValueType , FieldRenderProps < DynamicSelectFieldValueType > > , "component" > ,
4349 IdentifiableComponentInterface , TestableComponentInterface {
4450
4551 /**
@@ -63,17 +69,22 @@ export interface FieldSelectPropsInterface extends Omit<FieldProps<any, any, any
6369 */
6470 readOnly ?: boolean ;
6571 /**
66- * Validation of the field.
72+ * Validation of the field. Resolves to the error message, or to `undefined` when the value is valid.
6773 */
68- validation ?: ( value : string | number | any , allValues : Record < string , unknown > ) => any ;
74+ validation ?: (
75+ value : DynamicSelectFieldValueType ,
76+ allValues : Record < string , unknown >
77+ ) => string | undefined | Promise < string | undefined > ;
6978}
7079
7180/**
7281 * Implementation of the Select Field component of the dynamic form.
7382 *
7483 * @param props - Props injected to the component.
7584 */
76- export const FieldSelect = ( props : FieldSelectPropsInterface ) : ReactElement => {
85+ export const FieldSelect : FunctionComponent < FieldSelectPropsInterface > = (
86+ props : FieldSelectPropsInterface
87+ ) : ReactElement => {
7788
7889 const {
7990 hint,
@@ -93,12 +104,14 @@ export const FieldSelect = (props: FieldSelectPropsInterface): ReactElement => {
93104 < FormGroup >
94105 < FinalFormField
95106 name = { name }
96- parse = { ( value : any ) => value }
107+ parse = { ( value : DynamicSelectFieldValueType ) => value }
97108 initialValue = { initialValue }
98- validate = { ( value : any , allValues : Record < string , unknown > , meta : FieldState < any > ) =>
99- getValidation ( value , allValues , meta , required , validation )
100- }
101- render = { ( { input, meta } : FieldRenderProps < any > ) => (
109+ validate = { (
110+ value : DynamicSelectFieldValueType ,
111+ allValues : Record < string , unknown > ,
112+ meta : FieldState < DynamicSelectFieldValueType >
113+ ) => getValidation ( value , allValues , meta , required , validation ) }
114+ render = { ( { input, meta } : FieldRenderProps < DynamicSelectFieldValueType > ) => (
102115 < SelectFieldAdapter
103116 input = { input }
104117 meta = { meta }
0 commit comments