noahsalvi / svelte-use-form

The most compact reactive form controller (including Validation) that you'll ever see.
MIT License
252 stars 14 forks source link

Allow an alternate method to declare validators for a field #58

Closed keehun closed 1 year ago

keehun commented 1 year ago

The current method of using use:validators={} precludes being able to use children components in a form with svelte-use-form because you can't actually pass down functions as a prop—and even when the child component directly imports the validator and specifies the use:validators, it doesn't work (presumably because the use:form is in a different component?

It would be great if there was an alternate way of declaring a validator for a field so that we wouldn't have to pass down a function.

This is especially important when each field element has a lot of wrapper/other elements which normally would be wrapped in a component.

If there's already a way to do this, I would love to find out!

keehun commented 1 year ago

Oh! I just found the comment here https://github.com/noahsalvi/svelte-use-form/issues/37#issuecomment-1321003369 which specifies exactly how to do this—and is working very well.