You are passing hard-coded options to the component, but then expect to see dynamic ones upon form submission?..
What are you trying to achieve here?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I have an edit form on a modal that shows user profile information. The modal triggers successfully. However, all the other fields show the stored values except for the <Select /> element.
This is the <Select /> component:
export default function Select({id, name, onChange, className, options, placeholder, required,}) {
return (
<>
<select
className={
`border-gray-300 focus:border-indigo-200 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-xl shadow-sm sm:text-sm` +
className
}
name={name}
required={required}
id={id}
onChange={onChange}>
<option>{placeholder}</option>
{options.map((option, index) => {
return (
<option key={index} value={option.value}>
{option.label}
</option>
);
})}
</select>
</>
);
}
On the frontend, this is what I have:
const genderSelection = [
{ value: "M", label: "Male" },
{ value: "F", label: "Female" },
];
<Select defaultValue={data.gender} onChange={handleChange} options={genderSelection}
className={`block w-full sm:text-sm`} placeholder={`Select gender`} name={`gender`}
/>
This is the onChange() event:
const handleChange = (e) => {
setData({ ...data, [e.target.name]: e.target.value });
};
This is the useForm() data:
const { data, setData, processing, put, errors } = useForm({
name: auth.user.name,
email: auth.user.email,
gender: auth.user.gender,
mobile: auth.user.mobile_number,
});
The data in the <Select /> element gets updated when you submit the form, but it doesn't display the value from the database. Any help?
@Emokores in this component it isn't used
Here i added value
export default function Select({id, name, onChange, className, options, placeholder, required, value }) {
return (
<>
<select
value={value} //added
className={
`border-gray-300 focus:border-indigo-200 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-xl shadow-sm sm:text-sm` +
className
}
name={name}
required={required}
id={id}
onChange={onChange}>
<option>{placeholder}</option>
{options.map((option, index) => {
return (
<option key={index} value={option.value}>
{option.label}
</option>
);
})}
</select>
</>
);
}
Please or to participate in this conversation.