If someone has similar issue to me where even when using defaultValue it’s not set see if converting value to string with .toString()
helps.
For context:
I created a SelectField for related data inside a model and used CUID for ID of all tables.
Options are using the ID
as value
from query for all fileds in RelatedTable/Fields and defaultValue
is set based on current model’s relatedFieldId creted by Prisma/Redwood.
Might be related to me using CUID (as String)
instead of Integers
.
I am curious if anyone else had a similar issue.
<SelectField
name="relatedFieldId"
defaultValue={props.model.relatedFieldId.toString()} // toString() here is the key change it would not work without it!
className="rw-input"
errorClassName="rw-input rw-input-error"
>
{props.relatedFields?.map((relatedField) => {
return (
<option
key={relatedField?.id}
value={relatedField?.id}
>
{relatedField?.title}
</option>
);
})}
</SelectField>