How to autofocus a field in a form

Hi, is there a way to autofocus a form or specific field of a form when it’s rendered?

I am sending schema and uischema to frontend from backend and generate form based on that.

Here is the example:

I’ve noticed that when I’ve default values such as booleans, they are only set when user interacts with the form. So I was wondering can I trigger autofocus when form is rendered?

Hi @irakli-g,

the React Material renderer set supports a focus: true UI Schema option, e.g.

  type: 'Control',
  scope: '#/properties/name',
  options: {
    focus: true

The renderers then set Material UI’s autoFocus prop.

Regarding your code, you don’t need to switch between two JsonForms components to prevent handing over null. Setting data to undefined is the same as not handing it over so, so you can just use this:

  data={formData ?? undefined}
1 Like