Validations properties

These validations properties are external, available for your convenience and will be part of your final bundle if you use them.
Add them according to the order in which you want to apply your validations. Every property is a function that can be imported from aio-inputs except the custom property.
You have to write your custom validation function. If it returns something, it have to be an error message.

Properties list

  • required takes an error message
  • email takes an errorMessage
  • number takes an errorMessage
  • min takes a minimum acceptable value, an errorMessage and an optional boolean argument to validate as number
  • max takes a maximum acceptable value, an errorMessage and an optional boolean argument to validate as number
  • match copy and share same value and validations from another input. This is a typically password and confirmPassword use case. takes an input name to match and an errorMessage.
  • custommust be a synchronous function that takes the value entered by the user and return an error message or null.
    {
    validation:{
    custom:(value) =>{
    // make your validation
    returnvalueIsValid ?null:"new error message"
    },
    },
    },
    Copied
  • asyncCustom must be a function that should be called last in your validations. It takes the value entered by the user, a success callback and an error callback. .
    {
    validation:{
    asyncCustom:(value, onSuccess, onError) =>{
    // make your validation
    callServer(value)
    .then(valid =>onSuccess(valid ?null: "new error message"))
    .catch(error =>{
    onError()
    console.log(error)
    }
    )
    },
    },
    },
    Copied