Accepted

Accepted type

The accepted schema type is a special type you may use with HTML checkboxes. Please read the HTML forms and surprises guide to learn about the serialization behavior of the <input type="checkbox"> element.

The accepted type ensures the field is present and must have one of the following values.

  • "on"
  • "1"
  • "yes"
  • "true"

If validation passes, the value will be normalized to true.

import vine from '@vinejs/vine'
const schema = vine.object({
terms: vine.accepted()
})
const data = {
terms: 'on'
}
// output { terms: true }

Using the following modifiers, you may mark the field as optional or nullable.

See also: Working with undefined and null values

{
terms: vine.accepted().nullable()
}
{
terms: vine.accepted().optional()
}

Defining error message

You may define the custom error message using the accepted rule name.

const messages = {
accepted: 'The {{ field }} field must be accepted'
}
vine.messagesProvider = new SimpleMessagesProvider(messages)

On this page