T
TanStack2mo ago
yappiest-sapphire

is there fieldOptions constructor?

i'm trying to extract these field validator
return (

<form.AppField
name="title"
validators={{
onChangeAsyncDebounceMs: 500,
onChangeAsync: function ({ value }) {
const { error } =
CreateTicketSchema.shape.title.safeParse(value);
if (!error) {
return undefined;
}
return z.prettifyError(error);
},
}}
children={function (field) {
return (
<div
{...cy("textTitleField-div")}
className="w-full"
>
<field.TextField focus={true} />
</div>
);
}}
/>

);
return (

<form.AppField
name="title"
validators={{
onChangeAsyncDebounceMs: 500,
onChangeAsync: function ({ value }) {
const { error } =
CreateTicketSchema.shape.title.safeParse(value);
if (!error) {
return undefined;
}
return z.prettifyError(error);
},
}}
children={function (field) {
return (
<div
{...cy("textTitleField-div")}
className="w-full"
>
<field.TextField focus={true} />
</div>
);
}}
/>

);
but i'm loosing the types of the available parameters the properties are expected to have how do you guys deal with this? I'd rather not define them all in the parent form's formOptions where there exists a constructor for.
7 Replies
foreign-sapphire
foreign-sapphire2mo ago
not yet, but feel free to open a feature request issue on GH just to clarify, you‘d want to have it accessible in the logic section of a component, right?
yappiest-sapphire
yappiest-sapphireOP2mo ago
i think so, all i care about is being able to extract this validator to where i still have access to the types of the properties and parameters of the functions so i can reuse it in other Fields
foreign-sapphire
foreign-sapphire2mo ago
the main issue is that fieldOptions would need to know two things: the expected formOptions and the field.name. it'd be easier inside the component since we can make a helper function of sorts. It would drastically reduce the syntax. let me check if I have the proposal still somewhere would that work @bregue dhue ?
yappiest-sapphire
yappiest-sapphireOP2mo ago
yes, is this a feature that's available now?
foreign-sapphire
foreign-sapphire2mo ago
no, I haven't gotten around to do it yet. It's merely a thought on how it could look in the end we also don't have an open request for it as far as I know
yappiest-sapphire
yappiest-sapphireOP2mo ago
i'll do a feature request like you suggested, i just have to get to work soon,
foreign-sapphire
foreign-sapphire2mo ago
take your time! I have plenty on my backlog 👍

Did you find this page helpful?