Skip to content

🖥️ Frontend Issue — Dynamic Form Generation from SampleType.json_schema_url

🎯 Goal

Enhance the sample creation and editing forms to dynamically render type-specific input fields defined by the JSON Schema associated with each SampleType. This enables flexible metadata entry for different types of samples without hardcoding new fields in the frontend.


🧩 Implementation Details

1. Source of Schema

  • Each SampleType includes a json_schema_url that defines its structure.

  • When a user selects a sample type in the “Create Sample” or “Edit Sample” form:

    • Fetch the schema from the URL.
    • Parse and dynamically build the input fields.

2. Dynamic Form Generation

  • Parse the schema’s properties and required fields.
  • Generate form inputs (text, number, date, select, checkbox, etc.) according to JSON Schema type definitions.
  • Group inputs visually (e.g., sections or cards if schema defines sub-objects).
  • Required fields marked with * and validated client-side before submission.

3. Data Handling

  • All values entered in the dynamic fields will be collected under:

    "dynamic_sample_description": {...}

    and sent to the backend on create/update requests.

  • Backend validation results (if any) will be displayed inline.


4. UI/UX Enhancements

  • Add a collapsible “Additional Metadata” section showing dynamic fields.
  • Provide inline tooltips or schema-based description text.
  • Cache the fetched schema per sample type to minimize re-fetching.
  • Add client-side validation before submission based on the schema.

5. Example Flow

  1. User selects Sample Type: Battery.

  2. Frontend fetches schema from:

    https://sepia.helmholtz-berlin.de/sample-types/battery.json
  3. Dynamic form fields appear:

    • Cathode Material (text)
    • Anode Material (text)
    • Nominal Voltage (number)
  4. On save, sends:

    {
      "name": "Battery Sample A",
      "sample_type_id": 3,
      "dynamic_sample_description": {
        "cathode_material": "LiFePO4",
        "anode_material": "Graphite",
        "nominal_voltage": 3.7
      }
    }

🧪 Testing

  • Dynamic form generated for all sample types with schemas.
  • Fields render correctly per JSON Schema type.
  • Required fields enforced.
  • Invalid entries rejected with inline messages.
  • Works seamlessly in Create and Edit flows.

🏷️ Labels

frontend feature sample sample-type json-schema dynamic-form priority::high