Skip to content

Instantly share code, notes, and snippets.

@fand
Created January 17, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fand/6bb8f75428f4a261c8f5d6b09a4eda87 to your computer and use it in GitHub Desktop.
Save fand/6bb8f75428f4a261c8f5d6b09a4eda87 to your computer and use it in GitHub Desktop.
input要素をラップしてsetCustomValidityしてくれる君
const React = require('react');
class Validator extends React.Component {
static propTypes = {
inputProps : React.PropTypes.object.required,
isValid : React.PropTypes.boolean.required,
message : React.PropTypes.object.required,
}
componentWillReceiveProps (nextProps) {
const validity = nextProps.isValid ? '' : nextProps.message;
this.ref.setCustomValidity(validity);
}
render () {
return (
<input
{...this.props.inputProps}
ref={e => { this.input = e; }}/>
);
}
}
module.exports = Validator;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment