Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
React based HTML input for dollars that disallows decimals and inserts commas.
class NumericInput extends React.Component {
constructor(props = {}) {
super(props)
this.state = {
value: numeral(props.value).format('0,0')
}
}
onChange(e) {
var number = numeral().unformat(e.target.value)
var string = numeral(number).format('0,0')
this.setState({ value: string })
this.props.onChange(number)
}
render() {
return (
<input
className="form-control"
type="text"
placeholder={this.props.placeholder}
value={this.state.value}
onChange={this.onChange.bind(this)}/>)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.