@newskit-render/validation
TypeScript icon, indicating that this package has built-in type declarations

1.18.1 • Public • Published

@newskit-render/validation

A package for adding validation to my account.

How to use:

import initializeYupSchema, { OverrideYupSchemaType, ValidationFieldNames, } from '@newskit-render/validation'

import \* as yup from 'yup'

/_ Example of name validation override _/

const nameValidation = yup.object().shape({
  firstName: yup.string().required('First Name is required overriden'),
  lastName: yup.string().required('Last Name is required overriden'),
})

/_ Example of required fields override _/

const requiredFieldsOverride = [
  ValidationFieldNames.firstName,
  ValidationFieldNames.line1,
  ValidationFieldNames.mobile,
]

/_ Pass your override schema to here, so it's delegated accordingly _/

const overrideYupSchema: OverrideYupSchemaType = {
  name: nameValidation,
  options: {
    overrideRequiredFields: requiredFieldsOverride
  }
}

export default initializeYupSchema({overrideYupSchema})

Initializing Options

You can pass message templates, that will be used as the template of the required messages and wrong format messages.

export default initializeYupSchema({
  overrideYupSchema: overrideYupSchema,
  options: {
    requiredMessage: "Please enter your ${field}",
    wrongFormatMessage : '${field} is wrong format'
  }
})

Yup testing documentation .

Readme

Keywords

none

Package Sidebar

Install

npm i @newskit-render/validation

Weekly Downloads

183

Version

1.18.1

License

UNLICENSED

Unpacked Size

214 kB

Total Files

86

Last publish

Collaborators

  • newskit