Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Attribute filtering not clearing selected autocomplete value when invalid

## [10.0.0] - 2026-03-31

### Changed
Expand Down
6 changes: 3 additions & 3 deletions src/form-elements/FormElementAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ const AutocompleteFilter = React.memo(function AutocompleteFilter({
)

const handleChange = React.useCallback(
//useFormElementOptions expects the first arg to be the element
(element: FormTypes.FormElement, newValue: unknown) => onChange(newValue),
(element: FormTypes.FormElement, { value }: { value?: unknown }) => {
onChange(value as string | undefined)
},
[onChange],
)

Expand Down Expand Up @@ -249,7 +250,6 @@ function FormElementAutocomplete({
/>
)
}

return (
<AutocompleteFilter
{...props}
Expand Down
9 changes: 4 additions & 5 deletions src/hooks/useFormElementOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function useFormElementOptions<T>({
userProfileForInjectables,
])

//options that are shown based on conditional logic and user input
//options that are shown based on conditional logic, attributes, and user input
const filteredOptions = React.useMemo<FormTypes.ChoiceElementOption[]>(() => {
const reducedOptions = withInjectedOptions.filter(
(option) => !onFilter || (onFilter(option) && !option.displayAlways),
Expand All @@ -101,7 +101,7 @@ export default function useFormElementOptions<T>({

if (
typeof value === 'string' &&
!withInjectedOptions.some((option) => value === option.value)
!filteredOptions.some((option) => value === option.value)
) {
onChange(element, {
value: undefined,
Expand All @@ -111,7 +111,7 @@ export default function useFormElementOptions<T>({

if (Array.isArray(value)) {
const newValue = value.filter((selectedValue) =>
withInjectedOptions.some((option) => selectedValue === option.value),
filteredOptions.some((option) => selectedValue === option.value),
)
if (newValue.length !== value.length) {
const newValueArray = newValue.length ? newValue : undefined
Expand All @@ -122,11 +122,10 @@ export default function useFormElementOptions<T>({
}
}, [
element,
shownOptions,
onChange,
value,
conditionallyShownOptionsElement?.dependencyIsLoading,
withInjectedOptions,
filteredOptions,
])

useLoadDynamicOptionsEffect(element, onUpdateFormElements)
Expand Down
Loading