Skip to content

ui:fieldReplacesAnyOrOneOf: true and ui:field: "hidden" with custom field getting props like displayLabel, rawDescription... #4265

@smndtrl

Description

@smndtrl

Prerequisites

What theme are you using?

other

What is your question?

I'm working on a custom theme that also includes custom fields using a lightly modified copy core FieldTemplate. One of the custom for a custom oneOf property [1]. I'm dereferencing my schema and it looks like [2]. Because I don't want to show the selector for oneOf/anyOf I use "ui:fieldReplacesAnyOrOneOf": true and "ui:field": "hidden" which works fine. In addition I have set a field for '/schemas/specialString': StringOrReferenceField to show my custom field. Now I want to still render the FieldTemplate shell for the label, description and general accessibility however the props that arrive don't contain that information. For reference the props of my custom field [3].

From looking at

return (
<FieldTemplate {...fieldProps}>
<>
{field}
{/*
I can see that props that I would require only are passed to SchemaFields FieldTemplate and my own StringOrReferenceField gets
const field = (
<FieldComponent
{...props}
onChange={handleFieldComponentChange}
idSchema={idSchema}
schema={schema}
uiSchema={fieldUiSchema}
disabled={disabled}
readonly={readonly}
hideError={hideError}
autofocus={autofocus}
errorSchema={fieldErrorSchema}
formContext={formContext}
rawErrors={__errors}
/>
);

What is the best way for me to get my custom StringOrReferenceField to follow the FieldTemplate including displayLabel, description, help, etc.

Thank you in advance

[1]

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Schema for special string",
  "definitions": {
    "name": {
      "$id": "/schemas/specialString",
      "type": "object",
      "oneOf": [
        {
          "properties": {
            "reference": {
              "type": "string"
            }
          },
          "required": [
            "reference"
          ]
        },
        {
          "properties": {
            "static": {
              "type": "string"
            }
          },
          "required": [
            "static"
          ]
        }
      ]
    },
  }
}

[2]

{
  "type": "object",
  "required": [
    "url",
    "access_token",
    "input_field"
  ],
  "properties": {
    "url": {
      "type": "string",
      "description": "The URL of the API endpoint"
    },
    "access_token": {
      "$id": "/schemas/specialString",
      "type": "object",
      "oneOf": [
        {
          "properties": {
            "reference": {
              "type": "string"
            }
          },
          "required": [
            "reference"
          ]
        },
        {
          "properties": {
            "static": {
              "type": "string"
            }
          },
          "required": [
            "static"
          ]
        }
      ],
      "description": "The access token for fun"
    },
    "input_field": {
      "type": "string"
    }
  },
  "$schema": "http://json-schema.org/draft-04/schema#"
}

[3]
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions