0

I have been trying to implement a validation logic for duplicate name inputs. I have displayed some dynamic input fields for name input from an array and trying to add validations on it.

Expectations:

  1. when user type duplicates name on the fields there will be a validation errors shown beside the input fields.
  2. validation errors should be displayed with all the fields that contains the duplicate inputs(name)
  3. validations should occur on each input fields.

What I have tried so far: I am adding the link here for the details of the implementations. I am checking the input fields on onChange handlers and display error based on that on each index of the field. What I am getting currently is that: Errors are shown on each field based on the change event handlers, so moving on to the next fields errors are not shown even though it contains that same value.

What I am trying to achieve is that: Errors should be shown on each fields if it contains the duplicate values. Not like just showing the errors initially and whenever we move from that fields the validation doesn't work ( which is currently, I am having and it's wrong).

Can anybody help with this? I am also not sure what would be the best way of implementing this types of validations based on the current implementations I have. Any helps would be highly appreciated. Thanks in Advance.

Here is the link for the implementations: https://codesandbox.io/s/pedantic-bird-r979m?file=/src/Input.jsx:0-1648

1 Answer 1

2

Well, you can define errors as an array, each index of Input is an element of the array.

https://codesandbox.io/s/youthful-cdn-83t35?file=/src/Input.jsx

Sign up to request clarification or add additional context in comments.

1 Comment

oh,,this is what I have missed. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.