-
Notifications
You must be signed in to change notification settings - Fork 17
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
Setting value by array of ids #64
Comments
I'm not clear what you are asking. Please share the code you have so far to explain the issue better 😀 Also, have you looked through the examples on https://solid-select.com/ ? At a guess, https://solid-select.com/?example=Format or https://solid-select.com/?example=Format%2520%28Options%29 might help. |
I meant to be able to set the value of solid select like this: <Select value={1} or <Select value={[1,2,3]} instead of <Select value={{id:1,name="Test"}} |
🤔 You can set whatever you want as a value (e.g. If you can share a full example of what you want to achieve and where it is not working then I'll be able to guide better. |
I'm not sure why you'd want to do this, but maybe this is the sort of thing you are after? import { Select } from "@thisbeyond/solid-select";
import { createSignal } from "solid-js";
export const IndirectionExample = () => {
const options = [
{ id: 1, name: "apple" },
{ id: 2, name: "pear" },
];
const [value, setValue] = createSignal(1);
return (
<div
style={{
flex: 1,
display: "flex",
"flex-direction": "column",
gap: "8px",
}}
>
<Select
initialValue={value()}
options={options}
format={(item, type) =>
type === "option"
? item.name
: options.find((o) => o.id === item).name
}
optionToValue={(option) => option.id}
onChange={setValue}
/>
Current value: {value()}
</div>
);
}; |
Is it not possible to add a 'selectedOption' prop which takes a callback like so Also I noticed when the 'initialValue' is set you call onChange which is really not such a great idea. |
Is there a way to set the value of the solid select by using an index/key value instead of setting the value to and object or array of objects? So if my object is {id:1,name:"test"} I would want set value to 1 to select.
The text was updated successfully, but these errors were encountered: