Skip to content

DataForm: allow controls to be set as disabled #73673

@oandregal

Description

@oandregal

Related https://href.li/?https://github.com/WordPress/gutenberg/issues/73076

What problem does this address?

We have a way to set a field as "readOnly" which means that the field will use the render method in situations where the Edit one would have been used instead. For example, a text field set as readOnly will not display a input component in DataForm, but rather the result of computing its render function.

In addition to permanent non-editable fields, we also have the need for situational-non-editable fields. These fields should display disabled form controls.

What is your proposed solution?

Leverage the Edit config for field authors to be able to set a control as disabled.

Examples

A field that displays a disabled input control:

{
  type: 'text',
  Edit: {
    control: 'input',
    disabled: true
  }
}

A field that displays "hello, world!":

{
  type: 'text',
  Edit: {
    control: 'input',
    disabled: true
  },
  readOnly: true,
  render: () => "Hello, world"
}

Considerations for implementation

The Edit components are also used by the filters. In that scenario, there's no need to display a control as disabled. How do we handle that?

  • We cannot pass a new Edit config for filters because there's no one at that point. The NormalizeField we operate with has a control. See InputWidget component takes the field and prepares is (disables validation, etc.), and how getControl works. Perhaps we can make the EditConfig.disable a separate prop of the Edit component? There's already a operator prop that is only used in "filter mode" (ref).
  • Add a new filter prop in NormalizedFields that is created from Edit but removes the EditConfig.disabled config before creating the component.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] DataViewsWork surrounding upgrading and evolving views in the site editor and beyond[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions