Allowed values
The allowed values validator let's you ensure that a component has one of the specified values.
Example
- Code
- Example
import React from "react";
import {
createForm,
pageBreak,
textField,
StatefulFormView,
content,
allowedValues,
} from "@fab4m/fab4m";
import "@fab4m/fab4m/css/basic/basic.css";
const form = createForm({
city: textField({
label: "City",
validators: [
allowedValues(
["Gothenburg", "Stockholm"],
"Choose either Stockholm or Gothenburg"
),
],
required: true,
}),
break: pageBreak(),
content: content({}, () => <div>Great choice!</div>),
});
export default function TextFieldExample() {
return <StatefulFormView form={form} hideSubmit={true} />;
}