fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
5.67k stars 170 forks source link

Unable to enter multiple paths to forward method #635

Closed pavelrotek closed 1 month ago

pavelrotek commented 1 month ago

Hello Fabian,

according to forward method signature one would expect, that multiple fields can be used in pathList argument. But typescript doesn't allow that. I'd expect in this case that error will be forwarded to all fields listed in pathList.

Kind regards,

Pavel

fabian-hiller commented 1 month ago

Please share your schema with me. You can also use our playground if you like: https://valibot.dev/playground/

pavelrotek commented 1 month ago

See the example. I'd expect... if forward method has array as second argument then multiple props are possible. Typescript gives the error. Multiple props works somehow, but path in returned issues is different for password2 and password1.

https://valibot.dev/playground/?code=JYWwDg9gTgLgBAKjgQwM5wG5wGZQiOAcg2QBtgAjCGQgbgCh6BjCAO1XgGUmALAUxDI4AXkwA6MMDB8AFPTjiIFAFZ8mMGQG95cMGlQB3aABMAjAC5xk6TIxiOUYKwDmMgJQAacSCcAZPi4wPDIALG6eOnqohiYATJZ21rJ2Dk6unt5+Ac5BoeEe9AC+EXbY0AbIUMZyCna8agDWMlpRMVWmHq1GVbHFwgB8XSamwqNDPR7uA4QActRwqMggfIQRCgDahONmhB5b+t3GsYQAuvThDMxsHHBQfKgArqTwoinI2HwACpWostz8gi82gU2wsRBg9xgpl2kQOcUshAhHBhxUuLHYEFIfDEpAgrjuj2ebloQA

fabian-hiller commented 1 month ago

Is your goal to display the error message on both fields? This requires adding forward and check twice for each field

I recommend to just forward the error message to password2 and specify in the error message that both entries do not match.

pavelrotek commented 1 month ago

yes, sure... But my question is rather from API design point of view... If it is not intended to use forward with multiple fields, why the array is used? Just simple field is enough.

fabian-hiller commented 1 month ago

To forward issues to deeply nested fields. Have a look at this playground.

pavelrotek commented 1 month ago

Aaaa, ok, sorry for the question. My fault. it is clear now. closing