This worked really well! Much appreciated.
@sdirix i’ll update this reply to clean it up if you update your initial snippet to my small fix below.
I did end up creating basic UI Schemas for each JSON schema using
import { Generate } from "@jsonforms/react";
Generate.uiSchema(schema)
and was adding the nested password format to each as needed, but had only gotten through a few so this will save me significant time. For anyone coming across this, it turns out generating basic UI Schemas for each JSON Schema and incorporating the plumbing for getting those into the JsonForms component was worthwhile as I have already run into a few other edge cases where having a UI Scheme for positioning, formatting, etc. is nice to have.
Additionally, anyone trying this out should note a couple Syntax Errors in the above snippet. Below is my working code, and to help anyone running into a similar issue with custom renderers, the error I got was
Error: Element type is invalid
which comes from trying to destructure a non existent key in the Unwrapped
import
const { MaterialStringControl } = Unwrapped;
I checked what keys existed in the Unwrapped
import and noticed that MaterialStringControl
should be MaterialTextControl
.
Super basic, but the error message was a little obscure, so this may save someone 20 mins and improve the forum search for similar issues!
import { useMemo } from "react";
import { Unwrapped } from '@jsonforms/material-renderers'
import { rankWith, and, isStringControl, formatIs } from '@jsonforms/core';
import { withJsonFormsControlProps } from '@jsonforms/react';
const { MaterialTextControl } = Unwrapped;
const PasswordControl = (props) => {
const modifiedUiSchema = useMemo(() => ({ ...props.uischema, options: { ...props.uischema.options, format: 'password'}}), [props.uischema]);
return <MaterialTextControl {...props} uischema={modifiedUiSchema} />
}
const BoundPasswordControl = withJsonFormsControlProps(PasswordControl);
export const passwordRegistryEntry = {
renderer: BoundPasswordControl,
tester: rankWith(2, and(isStringControl, formatIs('password'))),
}
...
// In component using JSON Forms
...
import { materialRenderers } from "@jsonforms/material-renderers";
import { JsonForms } from "@jsonforms/react";
import { passwordRegistryEntry } from "./JSONFormPassword";
...
const renderers = [...materialRenderers, passwordRegistryEntry];
...
return (
...
<JsonForms
...
renderers={renderers}
...
/>
...
);