@rachelallyson/hero-hook-form 2.4.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.js +39 -10
- package/dist/react/index.d.ts +19 -1
- package/dist/react/index.js +39 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [2.5.1] - 2026-01-13
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **Conditional Field Helper TypeScript Types**: Fixed type inference issues in `FormFieldHelpers.conditional()`
|
|
10
|
+
- Added default generic type parameter `= FieldValues` for better type compatibility
|
|
11
|
+
- Updated to use type assertion pattern similar to `FormFieldHelpers.content()` for consistency
|
|
12
|
+
- Improved type safety and compatibility with explicit type annotations in condition functions
|
|
13
|
+
- When TypeScript can't infer the type from `Partial<T>`, explicitly specify: `FormFieldHelpers.conditional<YourType>(...)`
|
|
14
|
+
- Removed unused `ConditionalFieldConfig` import
|
|
15
|
+
|
|
16
|
+
## [2.5.0] - 2026-01-13
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- **AutocompleteField Component**: New autocomplete field component with full React Hook Form integration
|
|
21
|
+
- Supports static option lists via `items` prop
|
|
22
|
+
- Supports async loading via custom `children` render function
|
|
23
|
+
- Handles custom values with `allowsCustomValue` prop
|
|
24
|
+
- Full validation and error handling support
|
|
25
|
+
- Integrated with `FormFieldHelpers.autocomplete()` helper
|
|
26
|
+
- Integrated with `BasicFormBuilder.autocomplete()` method
|
|
27
|
+
- Comprehensive test coverage (10/10 tests passing)
|
|
28
|
+
- Example: `FormFieldHelpers.autocomplete("country", "Country", options, "Search for a country")`
|
|
29
|
+
|
|
30
|
+
### Dependencies
|
|
31
|
+
|
|
32
|
+
- Added `@heroui/autocomplete` as optional peer dependency and dev dependency
|
|
33
|
+
- Updated UI exports to include Autocomplete and AutocompleteItem components
|
|
34
|
+
|
|
5
35
|
## [2.4.0] - 2026-01-13
|
|
6
36
|
|
|
7
37
|
### Added
|
package/dist/index.d.ts
CHANGED
|
@@ -2083,6 +2083,13 @@ declare class BasicFormBuilder<T extends FieldValues> {
|
|
|
2083
2083
|
label: string;
|
|
2084
2084
|
value: string | number;
|
|
2085
2085
|
}[]): this;
|
|
2086
|
+
/**
|
|
2087
|
+
* Add an autocomplete field
|
|
2088
|
+
*/
|
|
2089
|
+
autocomplete(name: Path<T>, label: string, items: {
|
|
2090
|
+
label: string;
|
|
2091
|
+
value: string | number;
|
|
2092
|
+
}[], placeholder?: string): this;
|
|
2086
2093
|
/**
|
|
2087
2094
|
* Add a checkbox field
|
|
2088
2095
|
*/
|
|
@@ -2200,8 +2207,19 @@ declare const FormFieldHelpers: {
|
|
|
2200
2207
|
* FormFieldHelpers.input("phone", "Phone Number", "tel")
|
|
2201
2208
|
* )
|
|
2202
2209
|
* ```
|
|
2210
|
+
*
|
|
2211
|
+
* @example
|
|
2212
|
+
* With explicit type in condition function (similar to content helper pattern):
|
|
2213
|
+
* ```tsx
|
|
2214
|
+
* FormFieldHelpers.conditional(
|
|
2215
|
+
* "options",
|
|
2216
|
+
* (formData: Partial<z.infer<typeof fieldSchema>>) =>
|
|
2217
|
+
* formData.fieldType === 'DROPDOWN',
|
|
2218
|
+
* FormFieldHelpers.textarea("options", "Dropdown Options", "One per line")
|
|
2219
|
+
* )
|
|
2220
|
+
* ```
|
|
2203
2221
|
*/
|
|
2204
|
-
conditional: <T extends FieldValues>(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>) => ZodFormFieldConfig<T>;
|
|
2222
|
+
conditional: <T extends FieldValues = FieldValues>(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>) => ZodFormFieldConfig<T>;
|
|
2205
2223
|
/**
|
|
2206
2224
|
* Create a content field for headers, questions, or custom content between fields
|
|
2207
2225
|
*
|
package/dist/index.js
CHANGED
|
@@ -117,6 +117,9 @@ function AutocompleteField(props) {
|
|
|
117
117
|
name,
|
|
118
118
|
render: ({ field: field2, fieldState }) => {
|
|
119
119
|
const selectedKey = field2.value;
|
|
120
|
+
const hasSelectedValue = selectedKey != null && selectedKey !== "";
|
|
121
|
+
const allowsCustomValue = autocompleteProps?.allowsCustomValue ?? false;
|
|
122
|
+
const shouldShowInputValue = allowsCustomValue || !hasSelectedValue;
|
|
120
123
|
return /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement(
|
|
121
124
|
Autocomplete,
|
|
122
125
|
{
|
|
@@ -127,18 +130,18 @@ function AutocompleteField(props) {
|
|
|
127
130
|
isInvalid: Boolean(fieldState.error),
|
|
128
131
|
label,
|
|
129
132
|
placeholder,
|
|
130
|
-
selectedKey:
|
|
131
|
-
inputValue:
|
|
133
|
+
selectedKey: allowsCustomValue ? void 0 : hasSelectedValue ? String(selectedKey) : void 0,
|
|
134
|
+
inputValue: shouldShowInputValue ? field2.value ?? "" : void 0,
|
|
132
135
|
onSelectionChange: (key) => {
|
|
133
136
|
const next = key ?? "";
|
|
134
137
|
field2.onChange(next);
|
|
135
138
|
},
|
|
136
139
|
onInputChange: (value) => {
|
|
137
|
-
if (
|
|
140
|
+
if (allowsCustomValue) {
|
|
138
141
|
field2.onChange(value);
|
|
139
142
|
}
|
|
140
143
|
},
|
|
141
|
-
|
|
144
|
+
items
|
|
142
145
|
},
|
|
143
146
|
children ? children : (item) => /* @__PURE__ */ React.createElement(
|
|
144
147
|
AutocompleteItem,
|
|
@@ -2372,6 +2375,19 @@ var BasicFormBuilder = class {
|
|
|
2372
2375
|
});
|
|
2373
2376
|
return this;
|
|
2374
2377
|
}
|
|
2378
|
+
/**
|
|
2379
|
+
* Add an autocomplete field
|
|
2380
|
+
*/
|
|
2381
|
+
autocomplete(name, label, items, placeholder) {
|
|
2382
|
+
this.fields.push({
|
|
2383
|
+
autocompleteProps: placeholder ? { placeholder } : void 0,
|
|
2384
|
+
label,
|
|
2385
|
+
name,
|
|
2386
|
+
options: items,
|
|
2387
|
+
type: "autocomplete"
|
|
2388
|
+
});
|
|
2389
|
+
return this;
|
|
2390
|
+
}
|
|
2375
2391
|
/**
|
|
2376
2392
|
* Add a checkbox field
|
|
2377
2393
|
*/
|
|
@@ -2449,13 +2465,26 @@ var FormFieldHelpers = {
|
|
|
2449
2465
|
* FormFieldHelpers.input("phone", "Phone Number", "tel")
|
|
2450
2466
|
* )
|
|
2451
2467
|
* ```
|
|
2468
|
+
*
|
|
2469
|
+
* @example
|
|
2470
|
+
* With explicit type in condition function (similar to content helper pattern):
|
|
2471
|
+
* ```tsx
|
|
2472
|
+
* FormFieldHelpers.conditional(
|
|
2473
|
+
* "options",
|
|
2474
|
+
* (formData: Partial<z.infer<typeof fieldSchema>>) =>
|
|
2475
|
+
* formData.fieldType === 'DROPDOWN',
|
|
2476
|
+
* FormFieldHelpers.textarea("options", "Dropdown Options", "One per line")
|
|
2477
|
+
* )
|
|
2478
|
+
* ```
|
|
2452
2479
|
*/
|
|
2453
|
-
conditional: (name, condition, field2) =>
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2480
|
+
conditional: (name, condition, field2) => {
|
|
2481
|
+
return {
|
|
2482
|
+
condition,
|
|
2483
|
+
field: field2,
|
|
2484
|
+
name,
|
|
2485
|
+
type: "conditional"
|
|
2486
|
+
};
|
|
2487
|
+
},
|
|
2459
2488
|
/**
|
|
2460
2489
|
* Create a content field for headers, questions, or custom content between fields
|
|
2461
2490
|
*
|
package/dist/react/index.d.ts
CHANGED
|
@@ -2074,6 +2074,13 @@ declare class BasicFormBuilder<T extends FieldValues> {
|
|
|
2074
2074
|
label: string;
|
|
2075
2075
|
value: string | number;
|
|
2076
2076
|
}[]): this;
|
|
2077
|
+
/**
|
|
2078
|
+
* Add an autocomplete field
|
|
2079
|
+
*/
|
|
2080
|
+
autocomplete(name: Path<T>, label: string, items: {
|
|
2081
|
+
label: string;
|
|
2082
|
+
value: string | number;
|
|
2083
|
+
}[], placeholder?: string): this;
|
|
2077
2084
|
/**
|
|
2078
2085
|
* Add a checkbox field
|
|
2079
2086
|
*/
|
|
@@ -2191,8 +2198,19 @@ declare const FormFieldHelpers: {
|
|
|
2191
2198
|
* FormFieldHelpers.input("phone", "Phone Number", "tel")
|
|
2192
2199
|
* )
|
|
2193
2200
|
* ```
|
|
2201
|
+
*
|
|
2202
|
+
* @example
|
|
2203
|
+
* With explicit type in condition function (similar to content helper pattern):
|
|
2204
|
+
* ```tsx
|
|
2205
|
+
* FormFieldHelpers.conditional(
|
|
2206
|
+
* "options",
|
|
2207
|
+
* (formData: Partial<z.infer<typeof fieldSchema>>) =>
|
|
2208
|
+
* formData.fieldType === 'DROPDOWN',
|
|
2209
|
+
* FormFieldHelpers.textarea("options", "Dropdown Options", "One per line")
|
|
2210
|
+
* )
|
|
2211
|
+
* ```
|
|
2194
2212
|
*/
|
|
2195
|
-
conditional: <T extends FieldValues>(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>) => ZodFormFieldConfig<T>;
|
|
2213
|
+
conditional: <T extends FieldValues = FieldValues>(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>) => ZodFormFieldConfig<T>;
|
|
2196
2214
|
/**
|
|
2197
2215
|
* Create a content field for headers, questions, or custom content between fields
|
|
2198
2216
|
*
|
package/dist/react/index.js
CHANGED
|
@@ -123,6 +123,9 @@ function AutocompleteField(props) {
|
|
|
123
123
|
name,
|
|
124
124
|
render: ({ field: field2, fieldState }) => {
|
|
125
125
|
const selectedKey = field2.value;
|
|
126
|
+
const hasSelectedValue = selectedKey != null && selectedKey !== "";
|
|
127
|
+
const allowsCustomValue = autocompleteProps?.allowsCustomValue ?? false;
|
|
128
|
+
const shouldShowInputValue = allowsCustomValue || !hasSelectedValue;
|
|
126
129
|
return /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement(
|
|
127
130
|
Autocomplete,
|
|
128
131
|
{
|
|
@@ -133,18 +136,18 @@ function AutocompleteField(props) {
|
|
|
133
136
|
isInvalid: Boolean(fieldState.error),
|
|
134
137
|
label,
|
|
135
138
|
placeholder,
|
|
136
|
-
selectedKey:
|
|
137
|
-
inputValue:
|
|
139
|
+
selectedKey: allowsCustomValue ? void 0 : hasSelectedValue ? String(selectedKey) : void 0,
|
|
140
|
+
inputValue: shouldShowInputValue ? field2.value ?? "" : void 0,
|
|
138
141
|
onSelectionChange: (key) => {
|
|
139
142
|
const next = key ?? "";
|
|
140
143
|
field2.onChange(next);
|
|
141
144
|
},
|
|
142
145
|
onInputChange: (value) => {
|
|
143
|
-
if (
|
|
146
|
+
if (allowsCustomValue) {
|
|
144
147
|
field2.onChange(value);
|
|
145
148
|
}
|
|
146
149
|
},
|
|
147
|
-
|
|
150
|
+
items
|
|
148
151
|
},
|
|
149
152
|
children ? children : (item) => /* @__PURE__ */ React.createElement(
|
|
150
153
|
AutocompleteItem,
|
|
@@ -2378,6 +2381,19 @@ var BasicFormBuilder = class {
|
|
|
2378
2381
|
});
|
|
2379
2382
|
return this;
|
|
2380
2383
|
}
|
|
2384
|
+
/**
|
|
2385
|
+
* Add an autocomplete field
|
|
2386
|
+
*/
|
|
2387
|
+
autocomplete(name, label, items, placeholder) {
|
|
2388
|
+
this.fields.push({
|
|
2389
|
+
autocompleteProps: placeholder ? { placeholder } : void 0,
|
|
2390
|
+
label,
|
|
2391
|
+
name,
|
|
2392
|
+
options: items,
|
|
2393
|
+
type: "autocomplete"
|
|
2394
|
+
});
|
|
2395
|
+
return this;
|
|
2396
|
+
}
|
|
2381
2397
|
/**
|
|
2382
2398
|
* Add a checkbox field
|
|
2383
2399
|
*/
|
|
@@ -2455,13 +2471,26 @@ var FormFieldHelpers = {
|
|
|
2455
2471
|
* FormFieldHelpers.input("phone", "Phone Number", "tel")
|
|
2456
2472
|
* )
|
|
2457
2473
|
* ```
|
|
2474
|
+
*
|
|
2475
|
+
* @example
|
|
2476
|
+
* With explicit type in condition function (similar to content helper pattern):
|
|
2477
|
+
* ```tsx
|
|
2478
|
+
* FormFieldHelpers.conditional(
|
|
2479
|
+
* "options",
|
|
2480
|
+
* (formData: Partial<z.infer<typeof fieldSchema>>) =>
|
|
2481
|
+
* formData.fieldType === 'DROPDOWN',
|
|
2482
|
+
* FormFieldHelpers.textarea("options", "Dropdown Options", "One per line")
|
|
2483
|
+
* )
|
|
2484
|
+
* ```
|
|
2458
2485
|
*/
|
|
2459
|
-
conditional: (name, condition, field2) =>
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2486
|
+
conditional: (name, condition, field2) => {
|
|
2487
|
+
return {
|
|
2488
|
+
condition,
|
|
2489
|
+
field: field2,
|
|
2490
|
+
name,
|
|
2491
|
+
type: "conditional"
|
|
2492
|
+
};
|
|
2493
|
+
},
|
|
2465
2494
|
/**
|
|
2466
2495
|
* Create a content field for headers, questions, or custom content between fields
|
|
2467
2496
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rachelallyson/hero-hook-form",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "Typed form helpers that combine React Hook Form and HeroUI components.",
|
|
5
5
|
"author": "Rachel Higley",
|
|
6
6
|
"homepage": "https://rachelallyson.github.io/hero-hook-form/",
|