Я думаю, что вместо использования логики JSON вы можете написать собственный метод проверки в react-formio
. Где в зависимости от условия вы можете добавить свою логику. Код:
import React from "react";
import ReactDOM from "react-dom";
import { FormBuilder } from "react-formio";
import "./styles.css";
function App() {
return (
<div className="App">
<FormBuilder
form={{
components: [
{
input: true,
tableView: true,
inputType: "text",
inputMask: "",
label: "First Name",
key: "firstName",
placeholder: "Enter your first name",
prefix: "",
suffix: "",
multiple: false,
defaultValue: "",
protected: false,
unique: false,
persistent: true,
validate: {
required: false,
minLength: "",
maxLength: "",
pattern: "",
custom: "valid = (input.length< 5) ? 'Your input must be greater than 5':(input.length> 20) ? \n\"Your input must be less than 20\" \n : true;", //Your custom logic code
customPrivate: false
},
conditional: {
show: false,
when: null,
eq: ""
},
type: "textfield"
},
{
input: true,
tableView: true,
label: "Message",
key: "message",
placeholder: "What do you think?",
prefix: "",
suffix: "",
rows: 3,
multiple: false,
defaultValue: "",
protected: false,
persistent: true,
validate: {
required: false,
minLength: "",
maxLength: "",
pattern: "",
custom: ""
},
type: "textarea",
conditional: {
show: false,
when: null,
eq: ""
}
},
{
type: "button",
theme: "primary",
disableOnInvalid: true,
action: "submit",
block: false,
rightIcon: "",
leftIcon: "",
size: "md",
key: "submit",
tableView: false,
label: "Submit",
input: true
}
],
display: "form"
}}
onChange={schema => console.log(schema)}
/>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Вот демоверсия: https://codesandbox.io/s/cra-react-formio-niq10
Я бы предпочел вместо того, чтобы создавать свою собственную форму создания с этого сервера, и она должна быть легко подключаемой и играть. При добавлении JSON есть вероятность ошибки.