You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can currently implement your own AutoField and do whatever you want there, which is nice. You can also define a property universe.component to pass a react-component directly.
However, if you want to share schemas between server and client, you usually put the schemas in a shared location. But importing components there looks like the wrong place (it's also not possible if your componets resides in /client).
One solution is to simply extend the schema in a container, where you add the universe.component-property, but there is a better solution:
Having something like a mapping function, that can be provided to Autoforms or Autofields would be a good solution:
import {connectField, defaultComponentMapping} from 'uniforms';
import {createElement} from 'react';
const Auto = ({component = null, componentMapping = defaultComponentMapping, ...props}) => {
if (!component) {
component = componentMapping(props);
}
return createElement(component, props);
};
export default connectField(Auto, {includeInChain: false});
( i sketched the above code here, so it may contain errors)
defaultComponentMapping could be what we currently have in the AutoField (switch on props.fieldType, etc.)
You could then introduce your own properties on the schema, e.g. simply allow component to be a string:
export default new SimpleSchema({
file: {
type: String, // will be an url, .e.g from slingshot
uniforms: {
component: "SlingshotFileUploadField" // why not allow strings as well and map somewhere else the real component
}
}
});
and in your mappingFunction (somewhere in your client where its fine to import Components):
You can currently implement your own AutoField and do whatever you want there, which is nice. You can also define a property universe.component to pass a react-component directly.
However, if you want to share schemas between server and client, you usually put the schemas in a shared location. But importing components there looks like the wrong place (it's also not possible if your componets resides in /client).
One solution is to simply extend the schema in a container, where you add the universe.component-property, but there is a better solution:
Having something like a mapping function, that can be provided to Autoforms or Autofields would be a good solution:
( i sketched the above code here, so it may contain errors)
defaultComponentMapping
could be what we currently have in the AutoField (switch on props.fieldType, etc.)You could then introduce your own properties on the schema, e.g. simply allow component to be a string:
and in your mappingFunction (somewhere in your client where its fine to import Components):
Thoughts?
The text was updated successfully, but these errors were encountered: