Created
January 17, 2017 06:31
-
-
Save fand/6bb8f75428f4a261c8f5d6b09a4eda87 to your computer and use it in GitHub Desktop.
input要素をラップしてsetCustomValidityしてくれる君
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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