Simpler way to set errors after form submission
See original GitHub issueNot sure if it’s just me, but the process of showing errors on a form is a bit cumbersome:
import { setErrors } from '@formkit/vue'
- Set a unique ID on your form
- Invoke
setErrors()
with your unique ID
What if the form submission handler was passed a second parameter containing a node object?
function submit(value, node) {
node.setErrors(["Username not available."])
}
Implementation details free to be changed but something like this.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:7 (2 by maintainers)
Top Results From Across the Web
6 Form Error Message Mistakes Almost Everyone Makes
In your error messages, you want to sound positive, calm, and straightforward. You should also avoid blaming anyone or anything. Inserting ...
Read more >How to Report Errors in Forms: 10 Design Guidelines
1. Aim for Inline Validation Whenever Possible · 2. Indicate Successful Entry for Complex Fields · 3. Keep Error Messages Next to Fields...
Read more >How to create simple JavaScript error message from form ...
As a good way, you may make an object, like {fieldName:{errorMessage,validationRule}} , where is fieldName - is your field name, that you need ......
Read more >useForm - setError - React Hook Form
This method will force set isValid formState to false , however, it's important to aware isValid will always be derived by the validation...
Read more >Form Validation Errors - how to track them and what to do ...
In this article, we'll try to cover all different types of errors and how to ... These errors usually happen after a user...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@tosling solid points — one thing to note that will help with the unique ID thing is FormKit already produces unique IDs for you — you technically dont need to specify it yourself — but only explicitly specified ones end up in the global
getNode()
registry.For submitting forms, which is now in the beta.3 branch as of a few minutes ago, you can submit these forms 3 ways:
An alternative way to get a node is using the
@node
event which is emitted from all<FormKit>
components with the node as a payload. And in beta.3 you can also get the node via template ref:Playground example
I think @huzaifahj’s suggestion in great, and plan to implement it or something similar! I’m curious about your opposition to using
id
to reference core nodes @tosling. Our rational for ID vs template refs:FormKit
component which leads to quick misuse of the internalsThat said, the DX still has a ways to go in my opinion. On the note of DX — my eventual goal with the
form
type is to automatically handle errors for most “standard” requests, and you can provide an error adaptor (imagine alaravel
ordjango
error adapter) that automatically structures error responses into the acceptedsetErrors
format. We would leverage native fetch requests for you. An example API would be:Basically if the user provided an
endpoint
prop, we can assume responsibility for the submit handler and automatically catch any backend errors and set the on the form directly. This is an example of the kind of DX “enhancement” I’d like to see become reality, but what is currently published and available is still an early beta of the “fundamental” structures/api.