This is a migrated thread and some comments may be shown as answers.

Multiple validation errors

4 Answers 445 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vlad
Top achievements
Rank 1
Vlad asked on 24 Mar 2021, 04:44 PM
Is it possible to return multiple errors for one field via field or form lvl validator, and show them under field ? 

4 Answers, 1 is accepted

Sort by
0
Vlad
Top achievements
Rank 1
answered on 25 Mar 2021, 09:08 AM
Hello, any help on this ? I was thinkin about approach where I could build a string with separators and then pars them inside field component, but it look heavy, is there another way ?

Thanks in advice, Vlad
0
Krissy
Telerik team
answered on 25 Mar 2021, 01:55 PM

Hi Vlad,

What I can suggest is to create a function that will receive the validators and return a combination of the messages that they display. I've created an example to showcase how this can be achieved, enter 'test' to see how both validation messages appear: 

https://stackblitz.com/edit/react-multiple-validators?file=app/main.jsx

If you would like to have this as a feature, you can submit a feature request here. We can also do that for you if you prefer us to do it. The feature will be planned based on community interest.

Hope this is helpful.

Regards,
Krissy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Vlad
Top achievements
Rank 1
answered on 25 Mar 2021, 02:48 PM
Unfortunately with your example, it makes EmailInput always refreshing (if you add console inside component you will see that), and also `string[]` type is inconsistent with what we have inside doc and library, and cause we are using typescript, we have to use `any` for results. As I understood there are no other options to do that, correct ?
0
Krissy
Telerik team
answered on 29 Mar 2021, 05:02 AM

Hi Vlad, 

In regards to the EmailInput always refreshing, I was able to avoid that by making two changes to the previous example:

  1. I combined the validator outside of the render of the component, otherwise it creates a new array every single time and that makes the form continously re-render 
  2. Optional: Instead of using an array, all validation messages are combined into a single one with a particular symbol used as a separator. The string is then split where that separator is, and a new array is achieved.
    In regards to the `string[]` type being inconsistent - the suggestion I am offering is a workaround, which is why it may have some discrepancies. You can log a feature request and, in the meantime, use my suggestion until the feature is created. 

    Hope this is helpful.

    Regards,
    Krissy
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

    Tags
    General Discussions
    Asked by
    Vlad
    Top achievements
    Rank 1
    Answers by
    Vlad
    Top achievements
    Rank 1
    Krissy
    Telerik team
    Share this question
    or