How to access to the validation schema inside a FieldComponent?
Is there an easy way to leverage the validation schema inside a FieldComponent?
I'd like to know if the field is required or not, and if there are some rules like "max length"/"min length" to show a characters count.
Currently have this:
And this is my schema:
I'm looking to do something like this
{field.{somewhere}.isOptional && <span className="italic">—<Trans>optional</Trans></span>}

4 Replies
other-emerald•5mo ago
I believe the Validation Library you are using would need to provide information about that.
For the min/max chars you might be able to grab the Error that is returned by the Schema Lib.
I'm using Valibot and it returns Issues like this:
genetic-orangeOP•5mo ago
Yeah but you only know that when you have an error, supposedly after a submission
I'd like to know that before, as an information
other-emerald•5mo ago
I don't think there is more that TSF provides to help you in that case
genetic-orangeOP•5mo ago
I think I'm on to something. Arktype can transform a schema to a JSON Schema which looks like this:
Which I can then use in my use case.
I wonder if there is some way to "inject" that into TSF from a useForm() to re-use deeper, like in my case in a <form.AppField />
I suppose it could even be used for more accessibility stuff like adding
maxlength
to inputs