Skip to content

Commit 0924a41

Browse files
committed
fix(forms): FormAutocomplete options function now receive searchValue as an argument
1 parent d5cfd2e commit 0924a41

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

demo/FormExamples.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,14 @@ export function FormExamples() {
135135
<FormGroupAutocomplete
136136
name="autocompleteField2"
137137
label="Autocomplete that opens on focus"
138-
options={['Abcde', 'Fghij', 'klmno']}
138+
options={(formData, searchValue) => {
139+
if (searchValue.length < 2) {
140+
return ['Abcde', 'Fghij', 'klmno'];
141+
}
142+
143+
return ['1234', '2345', '3456'];
144+
}}
145+
onSearch={console.log}
139146
placeholder="Type some letters"
140147
openOnFocus={true}
141148
/>

src/forms/FormAutocomplete.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function FormAutocomplete({
2626
const registerRef = useCallback(register, []);
2727
const searchInputRef = useRef(null);
2828

29-
const items = normalizeOptions(options, getFormData());
29+
const items = normalizeOptions(options, getFormData(), searchValue);
3030
const value = getValue();
3131
const selectedItem = items.find((item) => item.value === value);
3232
const disabled = normalizeDisabled(_disabled, getFormData());

src/forms/helpers/form-helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export function handleInputChange(formState, event) {
3737
formState.update(name, value);
3838
}
3939

40-
export function normalizeOptions(options, formData) {
41-
const _options = typeof options === 'function' ? options(formData) : options;
40+
export function normalizeOptions(options, formData, extraData) {
41+
const _options = typeof options === 'function' ? options(formData, extraData) : options;
4242

4343
if (!Array.isArray(_options)) {
4444
throw new Error('Select Options should be an array');

0 commit comments

Comments
 (0)