Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const validate = (formValues, locale) => {
// To make it easier to attach errors during validation, we initialize
// all form fields to empty objects.
const errors = {
key: {},
name: {},
slug: {},
description: {},
inventory: {},
price: {},
};
// validate key
// Input elements usually provide a way to check whether it's value is empty
// This is useful to determine whether a required value was not filled out.
if (TextInput.isEmpty(formValues.key)) errors.key.missing = true;
// validate name
// A localized string is considered empty when no translation is given at all
if (LocalizedTextInput.isEmpty(formValues.name)) errors.name.missing = true;
// validate slug
// A slug must match [a-zA-Z0-9_-]{2,256}
// The error object of the slug is
// {
// missing: Boolean,
// translations: { de: { hasForbiddenChars: Boolean }, ... },
// }
// The "missing" part is used to highlight all fields, while the
// "translations" part gets mapped to errors per translation.
if (LocalizedTextInput.isEmpty(formValues.slug)) {
errors.slug.missing = true;
const validate = (formValues, locale) => {
// To make it easier to attach errors during validation, we initialize
// all form fields to empty objects.
const errors = {
key: {},
description: {},
inventory: {},
price: {},
};
// validate key
// Input elements usually provide a way to check whether it's value is empty
// This is useful to determine whether a required value was not filled out.
if (TextInput.isEmpty(formValues.key)) errors.key.missing = true;
// validate description
if (MultilineTextInput.isEmpty(formValues.description))
errors.description.missing = true;
// validate inventory
if (NumberInput.isEmpty(formValues.inventory)) {
errors.inventory.missing = true;
} else {
// When the value is not empty, we can assume that it is a number
if (formValues.inventory < 0) errors.inventory.negative = true;
if (NumberInput.hasFractionDigits(formValues.inventory))
errors.inventory.fractions = true;
}
// validate price
export const validate = values => {
const errorsByField = {
email: {},
password: {},
};
if (TextInput.isEmpty(values.email)) {
errorsByField.email.missing = true;
} else if (!emailRegex.test(values.email)) {
errorsByField.email.invalid = true;
}
if (TextInput.isEmpty(values.password)) errorsByField.password.missing = true;
return omitEmpty(errorsByField);
};
export const validate = values => {
const errorsByField = {
email: {},
password: {},
};
if (TextInput.isEmpty(values.email)) {
errorsByField.email.missing = true;
} else if (!emailRegex.test(values.email)) {
errorsByField.email.invalid = true;
}
if (TextInput.isEmpty(values.password)) errorsByField.password.missing = true;
return omitEmpty(errorsByField);
};
validate={formikValues => {
if (TextInput.isEmpty(formikValues.email)) {
return { email: { missing: true } };
}
return {};
}}
onSubmit={formikValues => {
validate={formikValues => {
if (TextInput.isEmpty(formikValues.email)) {
return { email: { missing: true } };
}
return {};
}}
onSubmit={formikValues => {
export const validate = values => {
const errorsByField = {
organizationName: {},
};
if (TextInput.isEmpty(values.organizationName)) {
errorsByField.organizationName.missing = true;
}
return omitEmpty(errorsByField);
};