Hi to all.
I’m playing around with RW Forms based on example from tutorial and I’m bit confused with service validation. To be precise, in Chapter 5, ‘Saving data’ part there is an example how to validate input on service level that shows how to validate multiple input fields:
validate(input.email, 'email', { email: true })
validate(input.name, 'name', {
inclusion: ['Audi', 'BMW', 'Ferrari', 'Lexus', 'Tesla'],
})
However, I noticed that, with code from tutorial, If I try to break more than one field validation (e.g. providing wrong e-mail address and wrong car make) I got only one error (in fact, result of first validation violation). What I realised is that validate method throws error so, first instance will break whole procedure. I don’t know is this by design or I misunderstood something but, would it be good to validate multiple fields and provide whole set of errors at once back to UI (to user). As mentioned on same page, would it be nice to have all errors on same place instead of pushing user to fix one-by-one? Is there any example how to return more than one error?
Also, regarding GraphQL error beeing returned to form, I’m curios would, in case of multiple validation, we would have single ‘BAD_USER_INPUT’ errors and then multiple messages in extensions.properties.messages section (one per each field) or it should be multiple graphQLErrors, one per each validation?
Also, I’m curious about ‘magic’ that RW forms is performing to convert this GQL error ‘mess’ into nicely formatted messages for FormError and field errors? Is it something that is bounded to RW controls (e.g. that controls itself filter out interesting data from messages) or it can be used as a helper function to be used with other form libraries (e.g. to get object containing just field error messages and use it further on). In my case,
Sorry in advance if all of these are noob questions but, I would appreciate any help.