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

Newly created options are not added to the options array correctly #170

Closed
Predator135 opened this issue May 25, 2023 · 4 comments
Closed
Labels

Comments

@Predator135
Copy link

Predator135 commented May 25, 2023

When creating a svelecte component with the creatable and keepCreated flags set, the newly created option is not displayed correctly in the options array on screen, it reads [Object] [Object].

I went into the code and pinpointed the area of the error and then fixed it, it was quite simple actually. On line 421 of the Svelecte.svelte file in the selectOption function (the line: if (keepCreated) options = [...options, opt];), the correct line should be: if (keepCreated) options = [...options, opt.value];. Instead of using the spread operator to add "opt" to the options array it should be "opt.value", remember that it is not a string but an object.

I didn't know how to address this in a pull request, but I hope this is also clear and you can fix it soon. It is resolved now in my code, but the next time I pull code from your repo the issue will be there again unless it is fixed. Greetings from the Netherlands.

@mskocik
Copy link
Owner

mskocik commented May 25, 2023

Not exactly. The options is array of objects, therefore opt and not opt.value.

Can you provide reproducible example in svelte REPL of your issue?

@Predator135
Copy link
Author

Yes that is correct, the options array is filled with objects, however, when pushing to that array from the line on 241 it pushes an object to the value field in the new object in the options array. So the options array ends up looking someting like [{value: {value: "value", label: "label"}, label: "label"}], while you would expect: [{value: "value", label: "label"}].

I am also not sure what the svelte REPL is, sorry.

@mskocik
Copy link
Owner

mskocik commented May 25, 2023

I am also not sure what the svelte REPL is, sorry.

Online environment (https://svelte.dev/repl/) where you can reproduce the issue you are having. I can't reproduce it myself.

@github-actions
Copy link

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 3 days.

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

No branches or pull requests

2 participants