Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ktaletsk opened this issue Sep 10, 2021 · 0 comments · Fixed by #69
Closed

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

ktaletsk opened this issue Sep 10, 2021 · 0 comments · Fixed by #69

Comments

@ktaletsk
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant