One Of
Require the value to be one of a fixed set of allowed values.
One Of
Validates that a value equals one of the items in a fixed list of allowed values. Useful for dropdowns, status fields, and single-choice questions.
Configuration
| Config flag | Type | Description |
|---|---|---|
oneOf | unknown[] | List of allowed values. |
oneOf | [unknown[], string] | Tuple form — the list plus a custom message. |
With useForm
const form = useForm({
initialValues: { status: '' },
validationSchema: {
status: { oneOf: ['active', 'paused', 'archived'] },
},
});With a custom message:
status: { oneOf: [['active', 'paused', 'archived'], 'Pick a valid status'] }With the V builder
import { V } from 'formify-js';
V.oneOf(['active', 'paused', 'archived']);Default message
| Scenario | Message |
|---|---|
| Value is not in the list | Must be one of: active, paused, archived (the list is generated from your values) |
Examples
| Value | Rule | Result |
|---|---|---|
'active' | oneOf: ['active', 'paused'] | ✅ Valid |
'deleted' | oneOf: ['active', 'paused'] | ❌ Invalid |
Notes
- Comparison is strict (
===) and case-sensitive:'Active'fails when the list contains'active'. - The default message names every allowed value, so users see exactly what is acceptable.
- Use
notOneOfwhen the requirement is the inverse (a blocklist).