material-ui-chip-input icon indicating copy to clipboard operation
material-ui-chip-input copied to clipboard

Form submission should be prevented of onBeforeAdd prevented chip creation

Open theKashey opened this issue 5 years ago • 2 comments

Scenario

  • you enter for example 123
  • you have onBeforeAdd to accept only 6 characters
  • it returns false
  • chip is not created
  • form is submitted

I am referring to this piece of code: https://github.com/TeamWertarbyte/material-ui-chip-input/blob/master/src/ChipInput.js#L391-L394

should be

 handleAddChip (chip) {
    if (this.props.onBeforeAdd && !this.props.onBeforeAdd(chip)) {
      this._preventChipCreation = true
      return chip ? true : false; // -> allow default only if there is no chip to add
    }

theKashey avatar Jul 20 '20 11:07 theKashey

Good suggestion, PR welcome @theKashey :)

leMaik avatar Sep 08 '20 13:09 leMaik

Hi guys, is it ok if I open this PR since it's inactive since September 2020? I'm really needing this fix. Thank you.

ghost avatar Jan 22 '21 13:01 ghost