Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated documentation on selection event #425

Open
justingolden21 opened this issue Apr 9, 2024 · 1 comment
Open

Updated documentation on selection event #425

justingolden21 opened this issue Apr 9, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@justingolden21
Copy link

Is your feature request related to a problem? Please describe.

It was difficult to figure out how to programmatically get the resulting selection when an autocomplete item is selected.

Thoroughly Describe the solution you'd like

Documentation on the selection event. Same code:

events: {
	input: {
		selection(event) {
			const feedback = event.detail;
			const selection = feedback.selection.value[feedback.selection.key];
			console.log(selection);
			console.log(feedback.selection);
		}
	}
}

Please provide a few use cases for this feature

  1. I imagine most programmers will want to do something with the data they select, otherwise there would be no reason to use this library other than for mockups

Please Describe alternatives you've considered

I searched through the docs on configuration and was unable to find it:

@justingolden21 justingolden21 added the enhancement New feature or request label Apr 9, 2024
@dombarnes
Copy link

If your autoComplete instance is assigned to a variable called autoCompleteJS then you should be able to access it:
In my case, each item in my data source is an object { key: 'MyKey", value: 'MyValue' }

events: {
      input: {
        selection: (event) => {
          const { selection } = event.detail
          console.log(selection.value) // the entry that was selected, either the string value or the object from your array
          searchField.input.value = selection.value.key // I'm then accessing my key property
        }
    }
}

In your example you're trying to access the an index on selected value as if its an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants