Multiple validation errors

5 posts, 0 answers
  1. Vlad
    Vlad avatar
    3 posts
    Member since:
    Mar 2021

    Posted 24 Mar Link to this post

    Is it possible to return multiple errors for one field via field or form lvl validator, and show them under field ? 
  2. Vlad
    Vlad avatar
    3 posts
    Member since:
    Mar 2021

    Posted 25 Mar Link to this post

    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
  3. Krissy
    Admin
    Krissy avatar
    23 posts

    Posted 25 Mar Link to this post

    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.

  4. Vlad
    Vlad avatar
    3 posts
    Member since:
    Mar 2021

    Posted 25 Mar in reply to Krissy Link to this post

    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 ?
  5. Krissy
    Admin
    Krissy avatar
    23 posts

    Posted 29 Mar Link to this post

    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/.

    Back to Top