Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce custom allowCreateRule #474

Closed
damusnet opened this issue Sep 23, 2015 · 1 comment
Closed

introduce custom allowCreateRule #474

damusnet opened this issue Sep 23, 2015 · 1 comment

Comments

@damusnet
Copy link

Hello, and thanks for open sourcing such a useful a nicely done component.

We have a scenario in multi mode where a user can create a new tag, but only if it is a valid email address. I would like to introduce a new allowCreateRule props that expects a function which would trigger the Add "newTag"? prompt only when matched.

Are there already any similar plans? Is this something you would consider merging? Do you have any advice?

Thanks in advance for your feedback.

@damusnet
Copy link
Author

Nevermind!

While trying to implement this allowCreateRule I realized it wasn't necessary and could be achieved with the current API. Here is my solution for reference:

  constructor(props) {
    super(props);
    this.state = {
      allowCreate: false,
    };
  }

  onInputChange(inputValue) {
    const re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    const allowCreate = re.test(inputValue);
    this.setState({
      allowCreate,
    });
  }

  render() {
    return (
      <Select
          multi
          allowCreate={this.state.allowCreate}
          onInputChange={this.onInputChange.bind(this)}
      />
    );
  }

Another testimony to how nice React - and this component - are 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant