Frequently Asked Questions
What is MuiForms?
MuiForms is a JSON-schema based form builder for React that uses Material-UI components. It allows you to define complex forms entirely through JSON schema without writing form HTML manually.
How do I get started?
Check the Getting Started → guide or follow the Installation → instructions.
Do I need to know Material-UI?
No, but it helps! MuiForms works with Material-UI components under the hood, but you interact with it through JSON schema.
Can I use it with TypeScript?
Yes! Full TypeScript support is available. See TypeScript Support →.
Schema & Configuration
How do I define a form schema?
Create a JSON object with a fields array containing field definitions. Each field needs name, and meta with displayName and displayType.
{
"fields": [
{
"name": "email",
"meta": {
"displayName": "Email Address",
"displayType": "email"
}
}
]
}How do I load a form using an API?
Fetch your schema from an API and pass it to MuiForms:
const [schema, setSchema] = useState(null);
useEffect(() => {
fetch('/api/forms/registration')
.then(r => r.json())
.then(data => setSchema(data));
}, []);
return schema ? <MuiForms schema={schema} onSubmit={handleSubmit} /> : null;What display types are available?
See the complete list in Field Types →. Common types include: text, email, number, select, checkbox, radio, date, file, textarea, and more.
How do I set default/initial values?
Use the value property in your field:
{
"name": "country",
"meta": {
"displayName": "Country",
"displayType": "select",
"value": "testCountryValue"
}
}Validation
How do I add validation?
Add a validation object to the field's meta:
{
"meta": {
"validation": {
"required": true,
"min": 5,
"max": 100
}
}
}How do I validate email addresses?
Use the email displayType, which validates automatically. Or use a pattern in a text field:
{
"meta": {
"displayType": "email",
"validation": {
"required": true
}
}
}How do I add custom validation?
Define a custom validator, pass it through the validators prop, and reference the validator name in meta.validation. The custom validation schema must include errorMsg; any other properties are passed to the validator as custom arguments.
const validators = {
validateEmail: (value, args) => {
return !value || String(value).includes('@');
}
};
<MuiForms schema={schema} validators={validators} onSubmit={handleSubmit} />{
"meta": {
"validation": {
"validateEmail": {
"errorMsg": "Invalid email format"
}
}
}
}Full custom validation guide →
Dynamic Behavior
How do I show/hide fields based on conditions?
Use the exists dependency:
{
"name": "taxId",
"meta": {
"displayName": "Tax ID",
"displayType": "text",
"dependencies": {
"exists": {
"ref": "accountType",
"value": "business"
}
}
}
}How do I create cascading dropdowns?
Use the loadOptions or options dependency:
{
"name": "state",
"meta": {
"displayType": "select",
"config": {
"url": "https://api.example.com/states",
"queryParams": [["country", { "type": "fieldValue", "ref": "country" }]],
"labelKey": "name",
"valueKey": "code"
},
"dependencies": {
"options": { "ref": "country" }
}
}
}How do I call an API when a field changes?
Use field events with onChange:
const fns = {
onCountryChange: (value) => {
fetch(`/api/country/${value}`)
.then(r => r.json())
.then(data => console.log('Country data:', data));
}
};How do I update a field property based on another field?
Use propUpdate dependency:
{
"dependencies": {
"propUpdate": {
"ref": "userType",
"propName": "displayName",
"valueMap": {
"personal": "Optional: Company Name",
"business": "Company Name (Required)"
}
}
}
}API & Remote Data
How do I load dropdown options lazily from an API?
Configure the config property:
{
"meta": {
"displayType": "select",
"config": {
"url": "https://api.example.com/products",
"urlType": "remote",
"labelKey": "name",
"valueKey": "id",
"lazy": true
}
}
}How do I add authentication headers to API calls?
Use the headers config property:
<MuiForms
schema={schema}
config={{
headers: {
'Authorization': `Bearer ${token}`
}
}}
onSubmit={handleSubmit}
/>How do I filter API results with query parameters?
Use queryParams in the field config:
{
"config": {
"url": "https://api.example.com/items",
"queryParams": [
["category", "electronics"],
["inStock", true]
]
}
}How do I handle API errors?
Check the API response and handle errors in your onError handler:
const handleError = (errors) => {
console.error('Form errors:', errors);
// Show error message to user
};
<MuiForms
schema={schema}
onSubmit={handleSubmit}
onError={handleError}
/>Styling & Layout
How do I change the appearance of fields?
Use the global config:
<MuiForms
schema={schema}
config={{
variant: 'filled', // outlined, filled, standard
size: 'small' // small, medium, large
}}
onSubmit={handleSubmit}
/>How do I make fields responsive?
Use displayProps for each field:
{
"meta": {
"displayProps": {
"xs": "12", // 100% on mobile
"md": "6", // 50% on tablet
"lg": "4" // 33% on desktop
}
}
}How do I add spacing between fields?
Use gapX and gapY in config:
<MuiForms
schema={schema}
config={{
gapX: 1, // Horizontal gap in rem
gapY: 1.5 // Vertical gap in rem
}}
onSubmit={handleSubmit}
/>How do I customize field styling?
Use custom CSS or Material-UI theme customization. See Styling →.
Form Submission
How do I handle form submission?
Implement the onSubmit callback:
const handleSubmit = (formData) => {
console.log('Form data:', formData);
// Send to API
};
<MuiForms schema={schema} onSubmit={handleSubmit} />How do I submit the form programmatically?
Get a ref to the form and call submit:
const formRef = useRef();
const handleSubmit = () => {
formRef.current?.submit();
};
return (
<>
<MuiForms ref={formRef} schema={schema} onSubmit={/*...*/} />
<Button onClick={handleSubmit}>Submit</Button>
</>
);How do I add custom submit and cancel buttons?
Use the buttons prop or modify the footer:
<MuiForms
schema={schema}
onSubmit={handleSubmit}
// Custom button configuration
/>Advanced Features
How do I use custom or complex field types?
Create a custom field component:
const CustomDateRange = (props) => {
// Your custom component
};
export default CustomDateRange;How do I handle file uploads?
Use the file displayType:
{
"name": "document",
"meta": {
"displayName": "Upload Document",
"displayType": "file"
}
}How do I preload form data?
Performance
How do I optimize API calls?
- Use
lazy: truefor large option lists - Implement debouncing for search fields
- Use server-side filtering with
queryParams - Batch related API calls
Troubleshooting
My field is not showing/hiding correctly
- Verify the
reffield name matches exactly - Check the field value using browser devtools
- Ensure the condition value matches the actual field value
API calls are not working
- Check CORS headers in Network tab
- Verify API endpoint is correct
- Check authentication headers are valid
- Test endpoint manually with curl/Postman
Cascading dropdowns not working
- Verify parent field has a value
- Check
queryParamsreferences correct field name - Ensure
dependencies.loadOptionsis configured - Test API endpoint with manual request
Validation not firing
- Verify
validationis in themetaobject - Check field name matches validation reference
- Test with browser console to see errors
- Ensure field is not hidden by dependencies
Discussions
-
Is there a way we can select the default tab other than the first tab in tabbed forms? Answer (opens in a new tab)
-
How to add custom cancel and save button in the Form? Answer (opens in a new tab)
-
How to use nested objects in form submit? Answer (opens in a new tab)
-
How to know the name or number of the current tab? Answer (opens in a new tab)