Skip to content

Ability to access validation state for form element #3952

Open
@asvae

Description

@asvae

Sometimes when we implement validated form - we need a way to check if field is valid to show it to user.

Something like this:
[password] ✅

Right now we have useForm composable, which allow us to check if field is valid from context of form, but this way

  • is not intuitive (I want to ask about input, not form) and input actually could have all validation features without a form wrapper;
  • and useForm().fields[].isValid doesn't account for dirty state - it's true until validation is run at least once.

Here are a couple of ideas I have (don't take these at face value and perform due investigation on your own):

  • make useFormElement composable, that would work similarly to useForm, allowing user to access validation features from ref
  • update useForm().fields to have isDirty param.
  • maybe for isValid - have a third option (null?) for case when validation wasn't run yet. That might not integrate with existing system at all though.

I believe end goal should be ability to use it something like this:

<va-input
  stateful
  ref="password"
  :success="password.isValid"
  :rules="passwordRules"
/>
const password = useFormElement('password')

Metadata

Metadata

Assignees

No one assigned

    Labels

    d3: mediumNo cheats. Monsters a bit faster.featureSomething useful to end userv2: nice to haveThis will make Vuestic feel better

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions