deathbeds / jupyterlab-starters

Starter notebooks and directories in JupyterLab

Home Page:https://jupyterstarters.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[jupyterlab-rjsf] Setting formData in SchemaForm has no effect

ktaletsk opened this issue · comments

Description

Setting formData has no effect, e.g.:

const schema = {
	  type: ["string"],
	};
const formData = "a";
const form = new SchemaForm(schema, {formData: formData});
layout.addWidget(form);

results in a empty input field. Same goes for any forms I tried.

Expected behavior

SchemaForm renders with data from formData.

Context

  • Operating System and version: WSL2 Ubuntu 20.04
  • Browser and version: Edge
  • JupyterLab version: 3.0.14
  • jupyter-starters version: N/A
  • @deathbeds/jupyterlab-rjsf: 1.0.2

Possible fixes

The issue seems to be with FormModel constructor.

SchemaForm.render() unpacks the variables from model:

const { schema, props, formData } = this.model;

However, model constructor never sets formData and it ends up being undefined.

Then, finalProps mixes props and formData (among other things)

const finalProps = {
// props from model
...props,
// assure a default prefix
idPrefix: this._idPrefix,
schema,
formData,
// overload classname
className,
validate: (formData: T, errors: rjsf.AjvError[]) => {
return errors;
},
// overload onChange
onChange: (evt: rjsf.IChangeEvent<T>, err?: rjsf.ErrorSchema) => {
this.onChange(evt, err);
if (props.onChange) {
props.onChange(evt, err);
}
},
};

Since props.formData (which comes from model) is undefined, formData ends up being undefined and not rendered.