add validation to all current inputs
validation right now is simply validating that the value is indeed a string
This commit is contained in:
@ -19,7 +19,7 @@ function defaultValue(type) {
|
|||||||
return defaults[type];
|
return defaults[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
function validatePosition(value) {
|
function validateString(value) {
|
||||||
if (!value && typeof value !== 'string') {
|
if (!value && typeof value !== 'string') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -32,12 +32,12 @@ export default contain({
|
|||||||
map({ form = {} }) {
|
map({ form = {} }) {
|
||||||
const {
|
const {
|
||||||
position = defaultValue('string'),
|
position = defaultValue('string'),
|
||||||
location = defaultValue('string'),
|
locale = defaultValue('string'),
|
||||||
description = defaultValue('string')
|
description = defaultValue('string')
|
||||||
} = form;
|
} = form;
|
||||||
return {
|
return {
|
||||||
position,
|
position,
|
||||||
location,
|
locale,
|
||||||
description
|
description
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -48,14 +48,16 @@ export default contain({
|
|||||||
propTypes: {
|
propTypes: {
|
||||||
jobActions: PropTypes.object,
|
jobActions: PropTypes.object,
|
||||||
position: PropTypes.object,
|
position: PropTypes.object,
|
||||||
location: PropTypes.object,
|
locale: PropTypes.object,
|
||||||
description: PropTypes.object
|
description: PropTypes.object
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
jobActions,
|
jobActions,
|
||||||
position
|
position,
|
||||||
|
locale,
|
||||||
|
description
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -77,7 +79,7 @@ export default contain({
|
|||||||
jobActions.handleForm({
|
jobActions.handleForm({
|
||||||
name: 'position',
|
name: 'position',
|
||||||
value,
|
value,
|
||||||
validator: validatePosition
|
validator: validateString
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
placeholder='Position'
|
placeholder='Position'
|
||||||
@ -85,16 +87,43 @@ export default contain({
|
|||||||
value={ position.value }
|
value={ position.value }
|
||||||
wrapperClassName='col-xs-10' />
|
wrapperClassName='col-xs-10' />
|
||||||
<Input
|
<Input
|
||||||
|
bsStyle={
|
||||||
|
!locale.valid && !locale.pristine ?
|
||||||
|
'error' :
|
||||||
|
null
|
||||||
|
}
|
||||||
label='Location'
|
label='Location'
|
||||||
labelClassName='col-xs-2'
|
labelClassName='col-xs-2'
|
||||||
|
onChange={ ({ target: { value } }) => {
|
||||||
|
jobActions.handleForm({
|
||||||
|
name: 'locale',
|
||||||
|
value,
|
||||||
|
validator: validateString
|
||||||
|
});
|
||||||
|
}}
|
||||||
placeholder='Location'
|
placeholder='Location'
|
||||||
type='text'
|
type='text'
|
||||||
|
value={ locale.value }
|
||||||
wrapperClassName='col-xs-10' />
|
wrapperClassName='col-xs-10' />
|
||||||
<Input
|
<Input
|
||||||
|
bsStyle={
|
||||||
|
!description.valid && !description.pristine ?
|
||||||
|
'error' :
|
||||||
|
null
|
||||||
|
}
|
||||||
label='Description'
|
label='Description'
|
||||||
labelClassName='col-xs-2'
|
labelClassName='col-xs-2'
|
||||||
|
onChange={ ({ target: { value } }) => {
|
||||||
|
jobActions.handleForm({
|
||||||
|
name: 'description',
|
||||||
|
value,
|
||||||
|
validator: validateString
|
||||||
|
});
|
||||||
|
}}
|
||||||
placeholder='Description'
|
placeholder='Description'
|
||||||
|
rows='10'
|
||||||
type='textarea'
|
type='textarea'
|
||||||
|
value={ description.value }
|
||||||
wrapperClassName='col-xs-10' />
|
wrapperClassName='col-xs-10' />
|
||||||
</form>
|
</form>
|
||||||
</Well>
|
</Well>
|
||||||
|
@ -47,11 +47,11 @@ export default Actions({
|
|||||||
if (!validator(value)) {
|
if (!validator(value)) {
|
||||||
return {
|
return {
|
||||||
transform(oldState) {
|
transform(oldState) {
|
||||||
const { oldForm } = oldState;
|
const { form } = oldState;
|
||||||
const newState = assign({}, oldState);
|
const newState = assign({}, oldState);
|
||||||
newState.form = assign(
|
newState.form = assign(
|
||||||
{},
|
{},
|
||||||
oldForm,
|
form,
|
||||||
{ [name]: { value, valid: false, pristine: false }}
|
{ [name]: { value, valid: false, pristine: false }}
|
||||||
);
|
);
|
||||||
return newState;
|
return newState;
|
||||||
@ -60,11 +60,11 @@ export default Actions({
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
transform(oldState) {
|
transform(oldState) {
|
||||||
const { oldForm } = oldState;
|
const { form } = oldState;
|
||||||
const newState = assign({}, oldState);
|
const newState = assign({}, oldState);
|
||||||
newState.form = assign(
|
newState.form = assign(
|
||||||
{},
|
{},
|
||||||
oldForm,
|
form,
|
||||||
{ [name]: { value, valid: true, pristine: false }}
|
{ [name]: { value, valid: true, pristine: false }}
|
||||||
);
|
);
|
||||||
return newState;
|
return newState;
|
||||||
|
Reference in New Issue
Block a user