Select
This field selects an option from a list of options.
Display type
- select
Field properties
| Name | Description |
|---|---|
| displayType | The displayType for this field (select) |
| displayName | The display name used for this field |
| options | The list of available options for the field |
| value | The value used by this field |
| placeholder | The hint value used for this field |
| isDisabled | Marks the field as disabled |
| isReadonly | Marks the field as readonly |
Config
The configuration defines how to load dropdown options for the select field. Use this to load options from remote api and configure its behaviour.
| Name | Description |
|---|---|
| url | The api endpoint to load dropdown options |
| urlType | Use urlType="remote" for calling third party api |
| pathParams | The path parameters of the url. Use this for dynamic path parameters |
| queryParams | List of query parameters. Use this for dynamic query parameters |
| requestType | Represents HTTP method used for url. Options are get, post, put, delete. If none is specified and url key is present, then default value is get |
| requestHeaders | A mapping of header key and value pairs. Use this for authentication, content type, caching policies, custom headers etc. |
| requestBody | A JSON payload. Parameters are representes as $0, $1 and so forth. Parameters are 0 indexed. |
| requestBodyParams | List of parameter values of request body. Each index value in the requestBodyParams represents the same index parameter form requestParams |
| valueKey | The key from the response for value of the field |
| labelKey | The key from the response for display name of the field |
| responseKey | The key from response which contains the results |
| lazy | Load options lazily. For example: load the options on opening dropdown |
Common Properties
Click here to go to common properties
Basic example
Schema
Query params
Query params can be used to pass additional data as part of the api url. This data can either be hardcoded or configured to pass data dynamically from other fields.
Format of query params: It accepts an array/list of query params.
[<QUERY_PARAM1>, <QUERY_PARAM2>,...]Format of query param: It accepts name and value in list like format.
[<NAME_OF_QUERY_PARAM>, <VALUE_OF_QUERY_PARAM>]- NAME_OF_QUERY_PARAM is just a string
- VALUE_OF_QUERY_PARAM can be a hardcoded value or can reference value from another field like this:
- type: 'fieldValue' indicates the value has to be taken from another field
- ref: name of the reference field from where value can be copied
Schema example with query params
Request Body
A sample request body payload for HTTP method 'post' with request body parameters and url.
Demo
Schema example
How to load options from remote api
Schema
How to load options from remote api that require auth
Approach 1: using request headers configured for specific field
Schema
Approach 2: using global config headers
Schema
Usage
import React from "react";
import MuiForms from "mui-forms";
import schema from "./schema.json";
function RatingForm() {
return (
<MuiForms
config={{
headers: {
"authorization": "Basic dGVzdHVzZXI6dGVzdHBhc3N3b3Jk"
}
}}
schema={schema}
onSubmit={() => {
// do nothing
}}
/>
);
}Error Handling
Handling Failed API Calls
When loading options from a remote API, handle failures gracefully:
{
"fields": [
{
"name": "product",
"meta": {
"displayName": "Select Product",
"displayType": "select",
"placeholder": "Loading products...",
"config": {
"url": "https://api.example.com/products",
"labelKey": "name",
"valueKey": "id",
"lazy": true
},
"validation": {
"required": true
}
}
}
]
}How to handle API errors with onError Callback
Use the onError callback to handle API failures globally across the form:
import React from "react";
import MuiForms from "mui-forms";
import schema from "./schema.json";
function MyForm() {
const handleErrorCallback = (error, section, field) => {
// error is the actual error from server
// section is the form section where the error occurred
// field is the source where api failure happened
console.error(`API Error in ${section}.${field}:`, error);
// Handle different error types
if (error.status === 401) {
// Handle authentication errors
console.error("Unauthorized - please login again");
} else if (error.status === 404) {
// Handle not found errors
console.error("Resource not found");
} else {
// Handle other errors
console.error("Failed to load products");
// showToast({ type: 'error', message: error.message });
}
};
return (
<MuiForms
onError={handleErrorCallback}
schema={schema}
onSubmit={(data) => {
// handle form submission
}}
/>
);
}
export default MyForm;Callback Parameters:
error- The error object returned from the API call (includes status, message, etc.)section- The form section where the error occurredfield- The specific field name that triggered the API error
Use cases:
- Log errors to monitoring/analytics services
- Show user-friendly error messages
- Retry failed API calls
- Update form state based on error type
Best Practices
When loading options from a remote API, handle failures gracefully:
Best Practices:
- Use the
lazyproperty to load options only when the dropdown opens - Provide a meaningful
placeholderthat indicates loading state - Set default options as fallback while data loads
- Validate required fields to ensure selection is made
Response Data Transformation
Use responseKey to extract data from nested API responses:
{
"config": {
"url": "https://api.example.com/data",
"responseKey": "results",
"labelKey": "displayName",
"valueKey": "id"
}
}If your API returns:
{
"results": [
{ "id": 1, "displayName": "Option 1" },
{ "id": 2, "displayName": "Option 2" }
]
}Common Patterns
Pattern 1: Static Options (Hardcoded)
Use this for small, fixed option lists:
{
"meta": {
"displayType": "select",
"options": [
{ "label": "Draft", "value": "draft" },
{ "label": "Published", "value": "published" },
{ "label": "Archived", "value": "archived" }
]
}
}When to use: Status fields, predefined categories, priority levels
Pattern 2: Remote API Options
Use this for large, dynamic option lists:
{
"meta": {
"displayType": "select",
"config": {
"url": "https://api.example.com/options",
"labelKey": "name",
"valueKey": "id",
"lazy": true
}
}
}When to use: User lists, product catalogs, geographic data
Pattern 3: Cascading Selects
Second select depends on first select value:
{
"fields": [
{
"name": "country",
"meta": {
"displayName": "Country",
"displayType": "select",
"config": {
"url": "https://api.example.com/countries",
"labelKey": "name",
"valueKey": "code"
}
}
},
{
"name": "state",
"meta": {
"displayName": "State",
"displayType": "select",
"config": {
"url": "https://api.example.com/states",
"queryParams": [
["country", { "type": "fieldValue", "ref": "country" }]
],
"labelKey": "name",
"valueKey": "code"
},
"dependencies": {
"exists": {
"field": "country",
"operator": "$notempty"
}
}
}
}
]
}Key points:
- Secondary select should only show when parent has a value
- Use
queryParamsto pass parent value to API - Use
dependenciesto hide/show based on parent selection
Pattern 4: Filtered Options with Search
Enable server-side filtering as user types:
{
"meta": {
"displayName": "Search User",
"displayType": "search",
"placeholder": "Type to search...",
"config": {
"url": "https://api.example.com/users/search",
"queryParams": [
["q", { "type": "fieldValue", "ref": "searchQuery" }]
],
"labelKey": "name",
"valueKey": "id"
}
}
}Performance Considerations
| Strategy | Benefit | When to Use |
|---|---|---|
lazy: true | Don't load options until dropdown opens | Large option lists (100+ items) |
queryParams | Filter server-side | Data that changes based on other fields |
responseKey | Extract nested data | Complex API responses |
| Static options | Instant loading, no network calls | Small, fixed lists |
| Caching | Reduce API calls | Stable data that loads frequently |
Recommended approach:
- Use static options for UI status, constants
- Use lazy loading for large remote datasets
- Use query parameters to filter at the source
- Implement backend caching for frequently accessed data
Troubleshooting Select Fields
| Issue | Solution |
|---|---|
| Options not loading | Check API URL, verify CORS headers, check network tab |
| Wrong labels/values shown | Verify labelKey and valueKey match response |
| Cascading not working | Ensure parent field has a value, check queryParams reference |
| Change event not firing | Check events configuration, verify field name in dependencies |
| Show/hide not working | Verify dependencies.exists condition matches actual field value |