Skip to content

Commit 2e9a798

Browse files
author
erikras-dinesh-agent
committed
Fix select multiple handling for both component and type props
- Add type parameter to buildFallbackFieldState - Check both component === 'select' and type === 'select' for multiple select handling - Ensures select multiple always returns array value even when initialValues has null
1 parent c52d897 commit 2e9a798

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/useField.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const buildFallbackFieldState = (
3737
initialValue: any,
3838
defaultValue: any,
3939
component: React.ComponentType<any> | "input" | "select" | "textarea" | undefined,
40+
type: string | undefined,
4041
multiple: boolean | undefined,
4142
allowNull: boolean | undefined,
4243
data: any,
@@ -56,7 +57,7 @@ const buildFallbackFieldState = (
5657
initial = initialValue;
5758
} else if (defaultValue !== undefined) {
5859
initial = defaultValue;
59-
} else if (component === "select" && multiple) {
60+
} else if ((component === "select" || type === "select") && multiple) {
6061
initial = [];
6162
}
6263

@@ -223,6 +224,7 @@ function useField<
223224
initialValue,
224225
defaultValue,
225226
component,
227+
type,
226228
multiple,
227229
allowNull,
228230
data,
@@ -244,6 +246,7 @@ function useField<
244246
initialValue,
245247
defaultValue,
246248
component,
249+
type,
247250
multiple,
248251
allowNull,
249252
data,
@@ -278,7 +281,7 @@ function useField<
278281
}
279282
}
280283

281-
if (component === "select" && multiple) {
284+
if ((component === "select" || type === "select") && multiple) {
282285
return Array.isArray(value) ? value : [];
283286
}
284287
// For checkboxes and radios, the `value` prop on the input element itself

0 commit comments

Comments
 (0)