Comments (4)
Hi @emmett08. It looks like you are creating a custom component. In that case, you probably want to wire it up with the form's model. Here's my first question - what is the checkboxes
in your example? Or rather, how would you like to use it?
Second thing is the AutoField
usage: are the field
and with
props specific application? These are not used in uniforms.
And lastly, remember that all fields rendered by uniforms have to be a part of the schema, and if you'd like to render some fields dynamically (e.g., make the number of fields depend on other fields), it has to be reflected in the schema too.
from uniforms.
Hi @radekmie - field was a github copilot addition which I didn't check. with
is what I'd like to have to pass an array to the component but not needed since I haven't wired the component to the forms model (I thought that was the function of connectField e.g. connectField<CheckboxListProps, unknown>(CheckboxList);
).
How do I pass in the choices array to the component when registering it in an AutoForm please?
const choices = [
{key: 'aws', label: 'AWS', checked: false, onChange: (event: React.ChangeEvent<HTMLInputElement>) => {console.log(event.target.checked)}},
{key: 'gcp', label: 'GCP', checked: false, onChange: (event: React.ChangeEvent<HTMLInputElement>) => {console.log(event.target.checked)}}
];
// custom uniforms component
// <CheckboxList checkboxes={choices} />
This is where I use the component and connectField:
export type VaultProps = HTMLFieldProps<string, HTMLDivElement> &
CheckboxListProps;
export const sourceApplicationLocations: CheckboxListProps = {
checkboxes: [
{
key: "aws",
label: "AWS",
checked: false,
onChange: (event: React.ChangeEvent<HTMLInputElement>) => {
console.log(event.target.checked);
},
},
{
key: "gcp",
label: "GCP",
checked: false,
onChange: (event: React.ChangeEvent<HTMLInputElement>) => {
console.log(event.target.checked);
},
},
],
};
const XOptions = connectField<CheckboxListProps, unknown>(CheckboxList);
export default XOptions;
from uniforms.
In case this helps anyone else...
import { Autocomplete, Box, Paper, TextField } from "@mui/material";
import { connectField, HTMLFieldProps } from "uniforms";
export type EnvironmentProps = HTMLFieldProps<string, HTMLDivElement> & {
environments: string[];
};
function Environment({ value, label, environments }:EnvironmentProps) {
const CustomPaper = (props: any) => {
return <Paper elevation={8} {...props} />;
};
return (
<Box sx={{ mt: 1, mb: 1 }}>
<Autocomplete
multiple
id="selected-environments-outlined"
// onChange={onSelectedValuesChange}
options={environments.map((option) => option)}
getOptionLabel={(option) => option}
isOptionEqualToValue={(a, b) => a === b}
PaperComponent={CustomPaper}
filterSelectedOptions
renderInput={(params) => (
<TextField
{...params}
variant="outlined"
label={label} // TODO: add props. This has no context
placeholder={value} // TODO: add props. This has no context
// onChange={handleOnChange}
/>
)}
/>
</Box>
);
}
export default connectField(Environment);
Usage:
export type EnvironmentsData = {
globalPlatform: string[];
};
const schema: JSONSchemaType<EnvironmentsData> = {
title: 'Environments Required',
type: 'object',
properties: {
globalPlatform: {
type: 'array',
minItems: 0,
items: {
type: 'string'
},
uniforms: { component: EnvironmentField, value: "Desired Platforms", label: 'Global', environments: ['Dev', 'Stage', 'Prod', 'Mgmt'] }
},
},
required: [],
};
from uniforms.
I'm glad you figured it out! Just to make it clear: what you proposed in this comment could work, but is not in-align with how uniforms are meant to be used. The onChange
should not be passed to any field, as a field is "just" a part of the form, not a standalone input.
And as for this code - you could simplify it a little. The Environment
components has no need to be wrapped in connectField
and it'd be enough to forward all of the props from it to the TextField
inside. If you'd need to read a value
or other prop, you can always use useField
to do that.
I'll close this one, but feel free to comment further.
from uniforms.
Related Issues (20)
- How to remove the time in data-time field? I only want date. HOT 2
- Overriding componentDetectorContext HOT 2
- How to scroll to error field? HOT 2
- Custom callback in onChange HOT 4
- Documentation v4
- Docusaurus 3
- [JSONSchemaBridge] Export `resolveIfNeeded` function HOT 3
- custom scalar type support in graphqlschemabridge HOT 2
- React 18
- Deprecate packages
- componentWillUnmount causing setState to be set to () => {} in Next.js HOT 3
- Array of arrays of object not showing inputs
- zod "lazy" support
- Support for jsonschema "const" keyword overriding "type"
- Add showInlineError to unstyled HOT 1
- Unknown type error for nullable() and nullish() HOT 1
- Error 'parent.value is undefined' for z.string().array().optional()
- Blank field gives error even though optional
- Support indeterminate checkbox HOT 2
- Add Example Of Progressive Disclosure HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uniforms.