-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Resolving options from promise breaks search function / use promise for options #274
Comments
Here's a reproducible snippet without backend request: let all_teams_resolved: object[] = $state([]);
onMount(async () => {
try {
all_teams_resolved = [
{
"id": 1,
"name": "Team1"
},
{
"id": 2,
"name": "Team2"
},
{
"id": 3,
"name": "Team3"
}];
} catch (error) {
console.error('Failed to fetch teams:', error);
all_teams_resolved = [];
}
}); |
Have you tried using <script>
function fetch_all_teams(json) {
return json.map((team) => team.name);
}
</script>
<Svelecte fetchCallback={fetch_all_teams} ... />
Seems like a bug. As a workaround you can specify searchProps <Svelecte searchProps={{fields: 'name'}} /> |
@Valentin-Metz bug was fixed, let me know if |
Now it works as expected, ty! |
@Valentin-Metz I am curious, why the I am talking about setup like this: <script>
function fetch_all_teams(json) {
return json.map((team) => team.name);
}
</script>
<Svelecte
fetch="/api/get_all_teams"
fetchCallback={fetch_all_teams}
...
/> Of course I don't have the whole picture if you are using |
Hi, I'm trying to do the following:
I have a backend API that returns
Ideally I'd like to be able to use a promise in the options directly (this is great for when my backend API returns a mapping not recognized by
fetch
or I want to make only one API call and use only a part of it for the options.If I try to work a round this with
and then use
options={all_teams_resolved}
, the options display correctly in the dropdown menu, but fail to be searchable.As soon as I type any letter all options disappear and I get a "No matching options".
The text was updated successfully, but these errors were encountered: