You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to export the schema to the frontend (React), where I dynamically convert it to Yup. However, I can't find a way to retrieve the rule names for each field (e.g., "string", "trim", "minLength", "maxLength", "email", "optional").
I've tried everything and still can't get the rule names. Instead, toJSON() only provides ref://X identifiers, which makes it difficult to dynamically map the rules.
⚠️ Workaround (Don't use this! You may lose it in the next versions of VineJS)
/*** Looks for the rule name within the function body by checking* what is in the second parameter of the `report("message", "ruleName", field)` function.*/exportfunctiongetRuleName(ref: string,refs: any): string{constfnBody=refs[ref].validator.toString()constmatch=fnBody.match(/report\s*\([^,]+,\s*([^,]+)/)if(match){returnmatch[1].trim().replace(/["']/g,'')}else{if(fnBody.includes('value.trim')){return'trim'}}return''}
Package: "@vinejs/vine": "^3.0.0"
Long life for VineJS!
Thanks in advance!
The text was updated successfully, but these errors were encountered:
Hi team, how are you? 😊
I'm trying to export the schema to the frontend (React), where I dynamically convert it to Yup. However, I can't find a way to retrieve the rule names for each field (e.g.,
"string"
,"trim"
,"minLength"
,"maxLength"
,"email"
,"optional"
).I've tried everything and still can't get the rule names. Instead,
toJSON()
only providesref://X
identifiers, which makes it difficult to dynamically map the rules.Here’s an example of my schema:
Current Output:
❌ Problem
toJSON()
output only includesref://X
identifiers instead of rule names.refs
are anonymous, so I can't extract their names.💡 Feature Request / Possible Solutions
Would it be possible to:
toJSON()
, alongside theref://X
identifiers?🔍 Expected Behavior
I would expect
toJSON()
to provide human-readable rule names like:Package: "@vinejs/vine": "^3.0.0"
Long life for VineJS!
Thanks in advance!
The text was updated successfully, but these errors were encountered: