olahol / react-tagsinput

Highly customizable React component for inputing tags.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ability to run custom validation func

th3fallen opened this issue · comments

Is it possible to run a custom function to validate a tag being added? what i need to validate is a bit to complex to be done via a single regex?

i pray the answer is not no...

commented

It's possible to just modify the onChange function and not add the tag if it's not valid.

That's what im doing at the moment but the issue im running into is in my onchange handler im validating and if it fails the validation it just nukes the current value so the input goes blank what i want is to keep the invalid value and show an error... heres' what im doing atm. Granted im going to move from doing tags.map to doing just the tag that's being added via the second param.

handleChange(tags) {
    let filteredTags = [];
    let data = { tags: filteredTags };
    tags.map((v) => {
      if (validator.isEmail(v) || validator.isMobilePhone(v, 'en-US')) {
        filteredTags.push(v);
        data.currentValue = '';
      }
    });
    this.setState(data);
  }