Skip to content

Instantly share code, notes, and snippets.

@marr
Last active August 29, 2015 14:22
Show Gist options
  • Save marr/7db1cd65609feccff01e to your computer and use it in GitHub Desktop.
Save marr/7db1cd65609feccff01e to your computer and use it in GitHub Desktop.
'use strict';
var object = require('isomorph/object')
var payment = require('payment');
var Input = require('newforms').Input
var React = require('react');
/**
* An HTML <input type="text"> widget.
* @constructor
* @extends {Input}
* @param {Object=} kwargs
*/
var TextInput = Input.extend({
constructor: function TextInput(kwargs) {
if (!(this instanceof TextInput)) { return new TextInput(kwargs) }
kwargs = object.extend({attrs: null}, kwargs)
if (kwargs.attrs != null) {
this.inputType = object.pop(kwargs.attrs, 'type', this.inputType)
}
Input.call(this, kwargs)
}
, inputType: 'tel'
})
module.exports = TextInput
var CCNumber = React.createClass({
componentDidMount: function() {
var node = React.findDOMNode(this);
payment.formatCardNumber(node);
},
render: function () {
return <input type={this.props.type} />
}
});
TextInput.prototype.render = function(name, value, kwargs) {
var finalAttrs = this.buildAttrs(kwargs.attrs, {
type: this.inputType,
name: name
})
return React.createElement(CCNumber, finalAttrs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment