do not convert null to a string when clearing out a typeahead field w/ burnettk (#373)

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
Kevin Burnett 2023-07-07 07:51:22 -07:00 committed by GitHub
parent 0801cc0292
commit 218a0f1f0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -114,7 +114,15 @@ export default function TypeaheadWidget({
onInputChange={typeaheadSearch}
onChange={(event: any) => {
setSelectedItem(event.selectedItem);
onChange(JSON.stringify(event.selectedItem));
let valueToUse = event.selectedItem;
// if the value is not truthy then do not stringify it
// otherwise things like null becomes "null"
if (valueToUse) {
valueToUse = JSON.stringify(valueToUse);
}
onChange(valueToUse);
}}
id={id}
items={items}