Skip to content

feat(group-array): support default values#245

Merged
sandrina-p merged 2 commits intomainfrom
rmt-xxx/default-values-on-group-arrays
Dec 2, 2025
Merged

feat(group-array): support default values#245
sandrina-p merged 2 commits intomainfrom
rmt-xxx/default-values-on-group-arrays

Conversation

@dragidavid
Copy link
Collaborator

@dragidavid dragidavid commented Nov 26, 2025

Problem

Consuming applications rely on field.default to apply default values to GROUP_ARRAY fields when they become visible conditionally. Two bugs prevented this:

  1. Missing defaults: field.default was undefined for GROUP_ARRAY fields after conditional schema processing, even when the JSON schema specified a default property.

  2. Incorrect inheritance: Inner fields were incorrectly inheriting the parent GROUP_ARRAY's default array instead of having undefined or their own defaults.

Cause

  1. During conditional schema merging, the default property was lost when fields were hidden and then shown again. The code used the processed schema (which lost defaults) instead of preserving them from originalSchema.

  2. When building inner fields, the code passed the GROUP_ARRAY schema as originalSchema instead of each inner field's own schema, causing the fallback logic to copy the parent's default array.

Solution (I think)

  1. Preserve defaults from originalSchema: Restore default from originalSchema when field.default is undefined, for both hidden and visible fields.

  2. Use correct schema for inner fields: Pass each inner field's original schema (originalSchema.items.properties[key]) instead of the GROUP_ARRAY schema when building inner fields.


json-schema to test:

{
  "additionalProperties": false,
  "type": "object",
  "x-jsf-order": [
    "has_team_members",
    "team_members"
  ],
  "properties": {
    "has_team_members": {
      "type": "string",
      "title": "Do you want to add team members?",
      "description": "Toggle this to show/hide the team members array.",
      "default": "no",
      "x-jsf-presentation": {
        "inputType": "radio",
        "direction": "column"
      },
      "oneOf": [
        {
          "title": "Yes, add team members",
          "const": "yes"
        },
        {
          "title": "No, skip team members",
          "const": "no"
        }
      ]
    },
    "team_members": {
      "type": "array",
      "title": "Team members",
      "x-jsf-presentation": {
        "inputType": "group-array"
      },
      "default": [
        {
          "member_name": "Alice Johnson",
          "role": "Developer"
        },
        {
          "member_name": "Bob Smith",
          "role": "Designer"
        }
      ],
      "items": {
        "type": "object",
        "properties": {
          "member_name": {
            "type": "string",
            "title": "Member Name"
          },
          "role": {
            "type": "string",
            "title": "Role",
            "x-jsf-presentation": {
              "inputType": "text"
            }
          }
        },
        "required": ["member_name"]
      }
    }
  },
  "required": ["has_team_members"],
  "allOf": [
    {
      "if": {
        "properties": {
          "has_team_members": {
            "const": "yes"
          }
        },
        "required": ["has_team_members"]
      },
      "then": {
        "required": ["team_members"]
      },
      "else": {
        "properties": {
          "team_members": false
        }
      }
    }
  ]
}

@sandrina-p sandrina-p changed the title feat(group-array): make defaults work on group arrays feat(group-array): support default values Dec 2, 2025
@sandrina-p sandrina-p force-pushed the rmt-xxx/default-values-on-group-arrays branch from 749ca33 to 85038b3 Compare December 2, 2025 14:09
@sandrina-p sandrina-p merged commit d304469 into main Dec 2, 2025
5 checks passed
@sandrina-p sandrina-p deleted the rmt-xxx/default-values-on-group-arrays branch December 2, 2025 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants