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

Run validation on submit #9

Closed ryanballa closed 3 years ago

ryanballa commented 3 years ago

Is there an example of how one would run validations on submit? I'd like to keep the submit active and allow users to click it but only proceed if no errors are present. I'd also like all the errors to show if they should be visible.

noahsalvi commented 3 years ago

Hey Ryan

I've now updated svelte-use-form to 2.2.0. By setting the new property touched on the $form object, you'll set touched = true to every form control in the form. This results in Hints being shown and the .touched class being added to the inputs. Since svelte-use-form validates on mount and when anything changes in the fields, a manual validation is not required.

Here's the example you're looking for REPL

And thanks for pointing out this use case!