Last active
August 29, 2015 14:22
-
-
Save marr/7db1cd65609feccff01e to your computer and use it in GitHub Desktop.
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
'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