How to use the yup.object function in yup

To help you get started, we’ve selected a few yup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github streamr-dev / streamr-platform / app / src / auth / components / RegisterPage / index.jsx View on Github external
useOnMount(() => {
        const invite = qs.parse(search).invite || ''

        // Set and validate `invite` on mount.
        setFormField('invite', invite)

        yup.object().shape({
            invite: yup.reach(schemas[0], 'invite'),
        }).validate({
            invite,
        }).then(
            () => {
                if (mountedRef.current) {
                    // To make sure that the registerPage invite doesn't stick in the browser history
                    replace(pathname)
                }
            },
            ({ message }: yup.ValidationError) => {
                if (mountedRef.current) {
                    setFieldError('name', message)
                }
            },
        )
github yalla-coop / connect5 / v2 / client / src / components / pages / Certificate / NameForm.js View on Github external
LoginForm,
} from './Certificate.style';

const name = Yup.string()
  .min(3)
  .required();

const email = Yup.string()
  .email()
  .required();

const nameSchema = Yup.object({
  name,
});

const nameEmailSchema = Yup.object({
  name,
  email,
});

export default class NameForm extends Component {
  state = {
    name: '',
    email: '',
    errors: {
      name: '',
      email: '',
    },
  };

  validate = async () => {
    const { location } = this.props;
github TheThingsNetwork / lorawan-stack / pkg / webui / console / components / pubsub-form / validation-schema.js View on Github external
.max(100, sharedMessages.validateTooLong)
        .required(sharedMessages.validateRequired),
      address: Yup.string()
        .matches(addressRegexp, sharedMessages.validateAddress)
        .required(sharedMessages.validateRequired),
      port: Yup.number()
        .integer(sharedMessages.validateInt32)
        .positive(sharedMessages.validateInt32)
        .required(sharedMessages.validateRequired),
      secure: Yup.boolean(),
    }),
    otherwise: Yup.object().strip(),
  }),
  mqtt: Yup.object().when('_provider', {
    is: 'mqtt',
    then: Yup.object().shape({
      server_url: Yup.string()
        .matches(mqttUrlRegexp, sharedMessages.validateUrl)
        .required(sharedMessages.validateRequired),
      client_id: Yup.string()
        .matches(idRegexp, sharedMessages.validateAlphanum)
        .min(2, sharedMessages.validateTooShort)
        .max(23, sharedMessages.validateTooLong)
        .required(sharedMessages.validateRequired),
      username: Yup.string()
        .matches(idRegexp, sharedMessages.validateAlphanum)
        .min(2, sharedMessages.validateTooShort)
        .max(100, sharedMessages.validateTooLong)
        .required(sharedMessages.validateRequired),
      password: Yup.string()
        .min(2, sharedMessages.validateTooShort)
        .max(100, sharedMessages.validateTooLong)
github GenesisVision / web-client / packages / social-trader / src / pages / profile / social-links / components / social-link / social-link-form.tsx View on Github external
validationSchema: (props: Props) =>
      object().shape({
        [FORM_FIELD.linkValue]: string()
          .trim()
          .max(
            100,
            props.t("profile-page.social-links.validation.link-max-length")
          )
      }),
    handleSubmit: (values, { props, setSubmitting, setFieldValue }) => {
github ZupIT / horusec-platform / manager / src / pages / Internal / Workspaces / Users / Edit / index.tsx View on Github external
const roles: Role[] = [
    {
      label: t('PERMISSIONS.ADMIN'),
      value: 'admin',
    },
    {
      label: t('PERMISSIONS.MEMBER'),
      value: 'member',
    },
  ];

  const [isLoading, setLoading] = useState(false);
  const [permissionsIsOpen, setPermissionsIsOpen] = useState(false);

  const ValidationScheme = Yup.object({
    role: Yup.string().oneOf(['admin', 'member']).required(),
  });

  type InitialValue = Yup.InferType;

  const initialValues: InitialValue = {
    role: userToEdit?.role,
  };

  return (
     {
        setLoading(true);
github jquense / react-formal / www / src / components / Editor.js View on Github external
import types from 'react-formal-inputs'
import * as yup from 'yup'
import Form from 'react-formal'

import { LiveProvider, LiveEditor, LiveError, LivePreview } from 'react-live'

import '../css/one-light.scss'

const MyDateInput = props => 

const nameSchema = yup
  .string()
  .default('')
  .required('You must provide a name')

const modelSchema = yup.object({
  name: yup.object({ first: nameSchema, last: nameSchema }),
  dateOfBirth: yup
    .date()
    .required('Please enter a date of birth')
    .max(new Date(), "You can't be born in the future!"),
  colorId: yup.number(),
  age: yup
    .number()
    .nullable()
    .required('Please enter an age')
    .positive('Ages must be a positive number'),
})

const reqMap = {
  react: React,
  'react-dom': ReactDOM,
github calluswhatyouwant / musicritic / src / components / signup / SignupForm.js View on Github external
touched={touched.passwordConfirm}
          value={values.passwordConfirm}
          onChange={handleChange}
          type="password"
        />
        <button disabled="{isSubmitting}" type="submit">
            Sign up for Musicritic
        </button>
    
);

export default withFormik({
    mapPropsToValues: () =&gt; ({
        username: '', email: '', password: '', passwordConfirm: '',
    }),
    validationSchema: Yup.object().shape({
        username: usernameValidator(),
        email: emailValidator(),
        password: passwordValidator(),
        passwordConfirm: passwordConfirmationValidator(Yup.ref('password')),
    }),
    handleSubmit: (values, { setSubmitting }) =&gt; {
        createUser(values).then(() =&gt; {
            setSubmitting(false);
            toast.success('User successfully created!');
        }).catch((error) =&gt; {
            setSubmitting(false);
            toast.error(error.message);
        });
    },
})(SignupForm);
github react-cross-platform / react-shop / src / modules / cart / CheckoutForm / CheckoutForm.tsx View on Github external
});
  };
}

const UPDATE_CART_MUTATION = gql(require("./updateCart.gql"));

const INITIAL_VALUES = {
  phone: "380"
};

export default compose(
  connect(),
  graphql(CART_QUERY),
  graphql(UPDATE_CART_MUTATION),
  withFormik({
    validationSchema: Yup.object().shape({
      phone: Yup.string().matches(/\d{12}/).required(),
      email: Yup.string().email()
    }),
    mapPropsToValues: (props: Props) =&gt; {
      const values = { ...props.data!.cart };
      for (const key in values) {
        if (!values[key] &amp;&amp; INITIAL_VALUES.hasOwnProperty(key)) {
          values[key] = INITIAL_VALUES[key];
        }
      }
      return values;
    },
    handleSubmit: (values, { props, setSubmitting, setErrors }) =&gt; {
      const { dispatch, mutate, data } = props;
      const { id } = data!.cart!;
      Modal.alert(
github plouc / wiremock-ui / src / modules / servers / components / CreateServer.tsx View on Github external
render() {
        const { createServer } = this.props

        return (
            
                <form>
                    <title>Create new server</title>
                     {
                            createServer({</form>