Skip to content

Add typed default values for all form response types and wire them into UI initialization#1130

Merged
JackWilb merged 7 commits intodevfrom
copilot/add-default-parameters-for-forms
Mar 4, 2026
Merged

Add typed default values for all form response types and wire them into UI initialization#1130
JackWilb merged 7 commits intodevfrom
copilot/add-default-parameters-for-forms

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

This issue adds optional defaults across UI form responses so Study Designers can prepopulate inputs in study configs, including complex matrix defaults. The parser types now model these defaults, and response initialization applies them consistently in form state.

  • Parser/type surface: add default to form-capable responses

    • Updated src/parser/types.ts to add optional default on:
      • numerical, shortText, longText, likert
      • dropdown, slider, radio, checkbox, buttons
      • matrix-radio / matrix-checkbox (typed as row-keyed defaults)
      • ranking-* responses
    • Matrix default type supports per-row scalar and multi-select values:
      • Record<string, string | string[]>
  • Form initialization: apply defaults centrally

    • Updated generateInitFields in src/components/response/utils.ts to seed values from response.default when no stored answer exists.
    • Preserved existing precedence for paramCapture query values.
    • Added shared default normalization helper used by initialization and reset flows.
  • Matrix defaults: normalize to existing internal encoding

    • Matrix checkbox row defaults provided as arrays are normalized to the existing pipe-delimited format ("a|b"), matching current matrix checkbox storage/dispatch behavior.
  • Reset behavior (withDontKnow): reset back to configured defaults

    • Updated ResponseSwitcher reset path to reuse the same default-normalization logic so toggling “I don’t know” restores configured defaults (instead of always empty values).
  • Schema + focused test updates

    • Regenerated StudyConfigSchema.json and LibraryConfigSchema.json to expose the new default fields.
    • Extended src/components/response/utils.spec.ts with default-initialization coverage, including matrix checkbox normalization.
const response: MatrixResponse = {
  id: 'matrix-default',
  type: 'matrix-checkbox',
  prompt: 'Matrix',
  answerOptions: ['A', 'B'],
  questionOptions: ['Q1', 'Q2'],
  default: {
    Q1: ['A', 'B'], // normalized to "A|B"
    Q2: 'A',
  },
};
UI screenshot: https://github.com/user-attachments/assets/14ec4a08-b7a1-4447-9cfa-068df9fd507a
Original prompt

This section details on the original issue you should resolve

<issue_title>Default parameters for all UI forms</issue_title>
<issue_description>We should allow (optional) default values for all kinds of form input elements where it's reasonable.

We need to update parser/types.ts to include this optional default on each response type. Then each form input component will need to be updated to handle this default value.

More complex types, like the matrix responses will have a more complex type for the default response.

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add optional default parameters for all UI forms Add typed default values for all form response types and wire them into UI initialization Mar 2, 2026
@JackWilb JackWilb marked this pull request as ready for review March 4, 2026 04:33
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

🪓 PR closed, deleted preview.

@JackWilb JackWilb force-pushed the copilot/add-default-parameters-for-forms branch from 9f001c4 to f163fd9 Compare March 4, 2026 04:34
@JackWilb JackWilb linked an issue Mar 4, 2026 that may be closed by this pull request
@JackWilb JackWilb merged commit 811493f into dev Mar 4, 2026
6 of 7 checks passed
@JackWilb JackWilb deleted the copilot/add-default-parameters-for-forms branch March 4, 2026 04:58
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.

Default parameters for all UI forms

2 participants