Commit 037062e3 authored by Matija Obreza's avatar Matija Obreza

Merge branch '146-forms-check-validators' into 'master'

Resolve "Forms: check for issues"

Closes #146

See merge request !125
parents 666c6fa4 acb530a7
......@@ -7,7 +7,8 @@
"invalidUrl": "Invalid URL",
"maxCharacters": "Must be {{count, number}} characters or less",
"invalidEmail": "Invalid email address",
"minValue": "Should be greater or equal to {{count, min}}"
"minValue": "Should be greater or equal to {{count, min}}",
"invalidDoi": "Invalid DOI. Must start with 10.[digits]/[something]"
},
"model": {
"_": {
......@@ -543,4 +544,4 @@
"active": "Active"
}
}
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@
"invalidUrl": "Invalid URL",
"maxCharacters": "Must be {{count, number}} characters or less",
"invalidEmail": "Invalid email address",
"minValue": "Should be greater or equal to {{count, min}}"
"minValue": "Should be greater or equal to {{count, min}}",
"invalidDoi": "Invalid DOI. Must start with 10.[digits]/[something]"
}
}
......@@ -14,3 +14,5 @@ export const maxLength = (max) => (value) => !value || value.length < max ? unde
export const emailAddress = (value) => !value || value.match(/^(?:[A-Za-z0-9!#$%&'*+\/=?^_\`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+\/=?^_\`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@([a-z0-9\-_]+\.)+([a-z]{2,4})$/) ? undefined : 'client:validations.invalidEmail';// eslint-disable-line
export const minValue = (min) => (value) => (value === undefined || isNaN(value) || value >= min) ? undefined : ['client:validations.minValue', { count: min }]; // `Should be greater than ${min}`;
export const validDoi = (value) => !value || value.match(/^10\.\d+\/.+/gi) ? undefined : 'client:validations.invalidDoi';
......@@ -3,7 +3,7 @@ import { createStyles, WithStyles, withStyles } from '@material-ui/core/styles';
import { WithTranslation, withTranslation } from 'react-i18next';
import { Button, Card, CardActions, Grid } from '@material-ui/core';
import * as React from 'react';
import { composeValidators, required, decimalNumber, minValue } from '@gringlobal/client/utilities/validators';
import { composeValidators, required, decimalNumber, minValue, validDoi } from '@gringlobal/client/utilities/validators';
import { PageSection } from '@gringlobal/client/ui/common/layout/Section';
import Accession from '@gringlobal/client/model/gringlobal/Accession';
import { TextField } from '@gringlobal/client/ui/common/form/TextField';
......@@ -65,7 +65,7 @@ class AccessionForm extends React.Component<IAccessionForm, any> {
component={ TextField }
className={ classes.textField }
label={ t('client:model.Accession.accessionNumberPart2') }
validate={ composeValidators(decimalNumber, minValue(0)) }
validate={ composeValidators(decimalNumber, minValue(-1)) }
/>
</Grid>
<Grid item xs={ 12 } sm={ 4 }>
......@@ -100,8 +100,7 @@ class AccessionForm extends React.Component<IAccessionForm, any> {
type="text"
component={ TextField }
label={ t('client:model.Accession.doi') }
required
validate={ required }
validate={ validDoi }
/>
</Grid>
</Grid>
......
......@@ -11,7 +11,7 @@ export const codeValue = [
];
function* listCodeValues(action) {
const codeValuesCall = yield select((state) => state.codeValue.codeValuesCall);
const codeValuesCall = yield select((state) => state.codeValue.public.codeValuesCall);
if (codeValuesCall && codeValuesCall.loading) {
console.log('Already loading codevalues');
return null;
......
......@@ -170,7 +170,7 @@ class UploadForm extends React.Component<IForm & WithTranslation & WithStyles> {
const mapStateToProps = (state, ownProps) => ({
ACCESSION_NAME_TYPE: state.codeValue.codeValuesCall && state.codeValue.codeValuesCall.data && state.codeValue.codeValuesCall.data.ACCESSION_NAME_TYPE,
ACCESSION_NAME_TYPE: state.codeValue.public.codeValuesCall && state.codeValue.public.codeValuesCall.data && state.codeValue.public.codeValuesCall.data.ACCESSION_NAME_TYPE,
incomingNames: state.inventorygroup.public.incomingNames,
});
......
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