Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the guide "Generate forms" with error handling #92

Closed
Rednas83 opened this issue May 25, 2020 · 2 comments
Closed

Update the guide "Generate forms" with error handling #92

Rednas83 opened this issue May 25, 2020 · 2 comments
Labels
feature request New feature or request

Comments

@Rednas83
Copy link

I am trying to raise an error as soon as the input value is different then "Rednas"
image
image
Tried:
data.name => works but of course if the name is set to name and only when in async because otherwise data is not initialized yet
@input="emit = $emit" => returns a function?

@Rednas83 Rednas83 added the feature request New feature or request label May 25, 2020
@justin-schroeder
Copy link
Member

Hey Rednas83.

I'm not entirely sure what’s youre trying to achieve, but you should not be writing your own mechanism for validation, and there is no need to tap into the input event. Your example would be easily solved using vue formulate's validation rules.

<FormulateInput
  v-for=-"item in items"
  :key="item.name"
  v-bind="item"
  validation="in:Rednas"
  :validation-messages="{
    in: 'That username is already taken'
  }"
/>

If you actually want to check the status of validation from the backend, you would write a custom validation rule.

The error prop is only when you want to explicitly pass in an error value, usually from the backend on submission. It's rare that you would need it.

@andrew-boyd wrote a nice article that uses some custom validators if you need an example: https://blog.logrocket.com/easier-more-robust-vue-forms-with-vue-formulate/

Docs on this: https://vueformulate.com/guide/validation/#custom-validation-rules

I'm going to close this for now since there's no bug or feature request here, but happy to carry on the conversation.

@Rednas83
Copy link
Author

Thanks for the example. That will work for me.

I only moved validation and validation-messages to items as well.

Also I figured out that I had to use $event instead of $emit to get the emitted value
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants