-
Notifications
You must be signed in to change notification settings - Fork 6
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
How to update or replace the list of values of an already created element? #38
Comments
Hi @AlChernova could you please clarify what you mean? Are you using If you're using the library to progressively enhance a |
Here's an example. Say you have a store locator and are asking the user to first pick a state and then showing them a list of stores in that state. The state names can be a fixed select element, but the list of stores changes each time the state is changed. I've been able to make this work by calling |
Hi @dmethvin-gov - sorry for my delayed reply. This is why multiple source approaches are supported. The most versatile one for providing different lists of results is of course providing a function as the source. But in this case, you'd need to do the filtering yourself. A pseudo-code example: const sourceFunction = (inputQuery, render, isFirstCall) => {
const baseSource = someCondition ? specificArrayOfConditions : defaultArrayOfOptions;
const resultsToRender = filterMyOptions(baseSource, inputQuery);
render(resultsToRender);
}; (Remember to also consider the UX of re-using the same field for multiple purposes though - e.g. is it clear to a screen-reader user). |
Thanks for the reply! The docs weren't clear to me and I thought the source function would only be called once. The function example doesn't say how often it's called, and something like a Promise can only resolve once. How often is the function called, and what triggers it? |
The |
Calling AriaAutocomplete on a select or checkbox list, or providing a static array, treats those as a static source. So that static list is stored internally, and the library then filters that static list each time the input value updates. It's only in those static cases that you'd need to destroy and re-initialise to update the list. But if you use a function (or Promise), or a string endpoint, then the source is dynamic and is called every time a new list of options needs to be rendered. Because in those scenarios, the library is relying on you doing the filtering yourself. That's the main difference. |
Your explanation makes total sense. Since I do want the built-in filtering (it's great!) but need to change the list based on other form fields, it sounds like the approach I'm taking (destroy and re-initialize) is easiest one to use. |
At the moment, yes. Which is unfortunate. Definitely a missing feature there! |
There is a , the list of which depends on other parameters. The hidden changes, but the outer list does not. How to update everything?
The text was updated successfully, but these errors were encountered: