Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow object key/value pairs to be added in the form #4437

Open
1 task done
kuhlaid opened this issue Jan 7, 2025 · 1 comment
Open
1 task done

Allow object key/value pairs to be added in the form #4437

kuhlaid opened this issue Jan 7, 2025 · 1 comment
Labels
awaiting response feature Is a feature request

Comments

@kuhlaid
Copy link

kuhlaid commented Jan 7, 2025

Prerequisites

What theme are you using?

core

Is your feature request related to a problem? Please describe.

I manage metadata for data tables generated from research surveys. Many variables of the data tables are categorical data, so a data value of "1" may represent "Yes". The number of keys and values varies wildly but I simply use strings for both key and value for simplicity (as there are other ways to define if the key/value pairs are numeric, string, etc. using other schema elements). An example of variable/columns with categorical data might be the following (where 'category' represents the data possibilities):

{
      "name": "E03PASKR",
      "surveyQuestion": "On MOST days of ANY ONE MONTH in the LAST 12 MONTHS did you have pain, aching, or stiffness in any of the following? Please rate as none, mild, moderate, or severe. - Right - Knee",
      "label": "Right Knee - pain, aching, or stiffness on MOST days of ANY ONE MONTH in the LAST 12 MONTHS",
      "source": "Online survey",
      "value": {
         "format": "categorical",
         "dataType": "Int64",
         "unique": "False",
         "category": {
            "0": "None",
            "1": "Mild",
            "2": "Moderate",
            "3": "Severe",
            "888": "No response"
         }
      }
   }

My schema typically looks like:

"category": {
  "title": "Categorical variable",
  "description": "For categorical variables, this value lists the numeric values and their labels.",
  "type": "object",
  "patternProperties": {
    "^.*$": {
      "type": "string"
    }
  }
}

It would be useful if the jsonschema form would allow a user to create object key/value string pairs of data. This would be similar to how arrays are handled in the form I'm assuming. Validation of patternProperties would likely be a nightmare so I'm not asking for that.

I had thought of splitting out my category keys and values into separate arrays, but I cannot have the keys and values disassociating from one another as they are explicitly linked together, so the possibility of the keys or values getting out of order in the arrays is preventing that approach.

Describe the solution you'd like

Instances of the following would trigger the form to allow the user to add string key/value pairs to a data object. No validation would be triggered. This would be a good starting point for addressing the need for key/value data pairs in the form.

  "patternProperties": {
    "^.*$": {
      "type": "string"
    }
  }

The form elements would function like an array with a new item button at the least (ordering would be nice). Instead on one field per item there would be two with maybe a simple format of the following per item (where the underlines represent data fields):

____________ : ____________

Describe alternatives you've considered

Again, I considered separate key/value arrays for my categorical data but the most important thing is that the key/value pair remain paired together. So separating the pairs into individual arrays can lead to data being mislabeled.

@kuhlaid kuhlaid added feature Is a feature request needs triage Initial label given, to be assigned correct labels and assigned labels Jan 7, 2025
@heath-freenome heath-freenome added awaiting response and removed needs triage Initial label given, to be assigned correct labels and assigned labels Jan 10, 2025
@heath-freenome
Copy link
Member

@kuhlaid Give the highly configurable nature of RJSF, you could create your own custom Field to do what you need. Off the top of my head I'm not quite sure how to go about implementing this. If you run into any issues in doing this, do reach out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response feature Is a feature request
Projects
None yet
Development

No branches or pull requests

2 participants