Commit dda8b9bb by Ari Rizzitano

validation fixes

parent b9b49d3c
...@@ -66,10 +66,12 @@ const asInput = (WrappedComponent) => { ...@@ -66,10 +66,12 @@ const asInput = (WrappedComponent) => {
} }
handleBlur(event) { handleBlur(event) {
const val = event.target.value;
if (this.props.validator) { if (this.props.validator) {
this.setState(this.props.validator); this.setState(this.props.validator(val));
} }
this.props.onBlur(event.target.value, this.props.name); this.props.onBlur(val, this.props.name);
} }
handleChange(event) { handleChange(event) {
...@@ -103,11 +105,11 @@ const asInput = (WrappedComponent) => { ...@@ -103,11 +105,11 @@ const asInput = (WrappedComponent) => {
NewComponent.defaultProps = { NewComponent.defaultProps = {
onChange: () => {}, onChange: () => {},
onBlur: () => {},
value: '', value: '',
description: undefined, description: undefined,
disabled: false, disabled: false,
required: false, required: false,
validator: () => {},
}; };
return NewComponent; return NewComponent;
......
...@@ -23,7 +23,7 @@ storiesOf('TextInput', module) ...@@ -23,7 +23,7 @@ storiesOf('TextInput', module)
name="username" name="username"
label="Username" label="Username"
description="The unique name that identifies you throughout the site." description="The unique name that identifies you throughout the site."
validate={(value) => { validator={(value) => {
let feedback = { isValid: true }; let feedback = { isValid: true };
if (value.length < 3) { if (value.length < 3) {
feedback = { feedback = {
...@@ -97,4 +97,29 @@ storiesOf('SelectInput', module) ...@@ -97,4 +97,29 @@ storiesOf('SelectInput', module)
}, },
]} ]}
/> />
))
.add('with validation', () => (
<SelectInput
name="skittles"
label="Favorite Color"
options={[
'',
'red',
'orange',
'yellow',
'green',
'blue',
'purple',
]}
validator={value => {
let feedback = { isValid: true };
if (!value) {
feedback = {
isValid: false,
validationMessage: 'Please make a selection.',
};
}
return feedback;
}}
/>
)); ));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment