Skip to content

Commit

Permalink
Changed the onChange handler to match other my components and updated…
Browse files Browse the repository at this point in the history
… code to reduce confusion. Also cleaned up with latest lint tests and verified it passed unit existing tests.
  • Loading branch information
manifestinteractive committed Jun 19, 2015
1 parent a9fdc3d commit 8bad636
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/components/input/code/templates/inputTemplate.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var React = require('react');
var classNames = require('classnames');

module.exports = function (component){
Expand All @@ -22,8 +21,7 @@ module.exports = function (component){
*/
var span;

if (component.state.error)
{
if (component.state.error){
span = ( <span className="input-group-span component-input-error">{component.state.error}</span> );
}

Expand All @@ -37,7 +35,7 @@ module.exports = function (component){
name={component.props.name}
id={component.props.id}
placeholder={component.props.placeholder}
onChange={component.changeHandler}
onChange={component.handleChange}
defaultValue={component.props.defaultValue}
disabled={component.props.disabled}
readOnly={component.props.readOnly}
Expand Down
20 changes: 9 additions & 11 deletions src/components/input/code/views/inputView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ module.exports = React.createClass({
required: React.PropTypes.bool,
valid: React.PropTypes.bool,
validator: React.PropTypes.string,
errorMessage: React.PropTypes.string,
onChange: React.PropTypes.func
errorMessage: React.PropTypes.string
},

getInitialState: function() {
return {
value: this.props.defaultValue || '',
error: null,
valid: true
}
};
},

getDefaultProps: function() {
Expand All @@ -35,30 +34,29 @@ module.exports = React.createClass({
disabled: false,
readOnly: false,
required: false,
onChange: this.changeHandler,
errorMessage: null
}
};
},

changeHandler: function(e) {
handleChange: function(e) {

var is_valid = true;
var isValid = true;
var error = null;
var self = this;
var value = e.target.value
var value = e.target.value;

clearTimeout(this.intent);
this.intent = setTimeout(function(){
if(value !== '' && typeof self.props.validator !== 'undefined'){
is_valid = self.props.validator.test(value);
isValid = self.props.validator.test(value);
}

if( !is_valid){
if( !isValid){
error = self.props.errorMessage;
}

self.setState({
valid: is_valid,
valid: isValid,
error: error
});
}, 500);
Expand Down

0 comments on commit 8bad636

Please sign in to comment.