Skip to content

Commit 644d8af

Browse files
author
Dustyn Blackmore
committed
0.1.4 Build Preparation
1 parent 9e0713a commit 644d8af

3 files changed

Lines changed: 48 additions & 64 deletions

File tree

dist/react-component_input.js

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,12 @@ var Input = function (_Component) {
463463
ourCallbackResult = false;
464464
break;
465465
}
466+
467+
// Handles initial validation state (Triggered for error message)
468+
if (this.props.validation) {
469+
this.handleHasValidation();
470+
}
471+
466472
if (ourCallbackResult !== "") {
467473
this.setState({
468474
onComponentDidMountCallback: ourCallbackResult
@@ -541,20 +547,8 @@ var Input = function (_Component) {
541547
var thisValue = null;
542548

543549
switch (this.props.type) {
544-
case "button":
545-
thisValue = clonedEvent.target.value;
546-
break;
547-
case "radio":
548-
thisValue = clonedEvent.target.value;
549-
break;
550-
case "text":
551-
thisValue = clonedEvent.target.value;
552-
break;
553-
case "textarea":
554-
thisValue = clonedEvent.target.value;
555-
break;
556550
default:
557-
thisValue = clonedEvent.target.value || clonedEvent.value || false;
551+
thisValue = clonedEvent.target.value;
558552
break;
559553
}
560554

@@ -729,31 +723,25 @@ var Input = function (_Component) {
729723
key: "handleHasValidation",
730724
value: function handleHasValidation(event) {
731725
var value = undefined;
732-
switch (this.props.type) {
733-
case "radio":
734-
value = event.target.on;
735-
break;
736-
737-
case "text":
738-
value = event.target.value;
739-
break;
740-
741-
case "textarea":
742-
value = event.target.value;
743-
break;
744726

745-
default:
746-
value = true;
747-
break;
727+
// Handles initial validation state, which does not include an event.
728+
if (event) {
729+
switch (this.props.type) {
730+
default:
731+
value = event.target.value;
732+
break;
733+
}
734+
} else {
735+
value = this.state.value;
748736
}
749737
var validationResult = undefined;
750-
var validationFailureIndex = -1;
738+
751739
if (this.props.validation instanceof Array) {
752740
validationResult = this.props.validation.map(function (aFunction) {
753741
return aFunction.callback(value);
754742
});
755743

756-
validationFailureIndex = validationResult.indexOf(false);
744+
var validationFailureIndex = validationResult.indexOf(false);
757745
if (validationFailureIndex === -1) {
758746
validationResult = true;
759747
} else {
@@ -771,6 +759,10 @@ var Input = function (_Component) {
771759
}
772760
}
773761

762+
if (validationResult) {
763+
this.setState({ validationErrorMessage: '' });
764+
};
765+
774766
this.setState({
775767
isValid: validationResult
776768
});
@@ -872,7 +864,7 @@ var Input = function (_Component) {
872864
thisValidation = _react2.default.createElement(
873865
"p",
874866
{ className: validationClassNames },
875-
this.state.validationErrorMessage || "invalid"
867+
this.state.validationErrorMessage
876868
);
877869
}
878870

0 commit comments

Comments
 (0)