score:1

Accepted answer

well what you can do is make the number inputs controlled by storing their values in the store:

state = {
  // other state,
  inputs: {}
}

then in onchangehandler set the value of each input in the state:

function onchangehandler(e) {
  const { name, value } = e.target;

  this.setstate({
    inputs: {
      ...this.state.inputs,
      [name]: value
    }
  })
}

then when your form is submitted you can add a check to see if the values are unique or not, there are many ways to do that, what i'm doing here is remove the duplicates from the array and then check the length of the array against the values in the state like this:

function handleseedingsubmit(e) {
  e.preventdefault();
  const { inputs } = this.state;
  const valuesinstate = object.values(input);
  const uniquevaluesarr = [...new set(valuesinstate)];

  const areinputsvalid = valuesinstate.length === uniquevaluesarr.length;
  if (!areinputsvalid) {
    // set error here
    return;
  }

  // hurray!! inputs are valid
  // handle success case here
}

hope it helps :)


Related Query

More Query from same tag