Appearance
Overview
In this section, we will create a customized upload form with an emphasis on the metadata schema customization.
Prerequisites
This tutorial is an expansion of the custom upload form creation. You must be familiar with JSON (JavaScript Object Notation).
Example - New Species
In our example, we are part of a biology lab where users are specialized in the study of the animal kingdom (field). In one of our topics, we want a customized upload form to gather data about new species.
Inputs
Since the nodes is a required attribute in the Form Definition, we will focus on the inputs first.
Here are a few inputs that we want to capture and their expected type:
- Binomial Nomenclature - a short text input
- Physical Description - a long text input
- Phylum - a dropdown selection box with a single selection option
- Population Estimates - a number input
Inputs - Binomial Nomenclature
This input is a text type.
Let's start with the minimum requirements:
json
{
"nodes": [
{
"type": "text",
"id": "Binomial Nomenclature",
"label": "Binomial Nomenclature",
"path": "Binomial Nomenclature"
}
]
}In this example, id, label, and path can have the same values. The most important value is the id, which must be unique within the nodes. The label is what the users will actually see as the label of the input in the upload form.
The path determines how we will store the value - must also be unique. For example, if we change the value to bn, then the exported metadata becomes:
json
{
"bn": {
"label": "Binomial Nomenclature",
"value": "xxx"
}
}IMPORTANT
You must include a path. If omitted, the input value will not be saved.
Inputs - Physical Description
This input is a textarea type.
Type becomes textarea and a row value must be included to determine the size of the text box.
json
{
"type": "textarea",
"id": "Physical Description",
"label": "Physical Description",
"path": "Physical Description",
"rows": 4
}Inputs - Phylum
This input is a selection type.
Here is the added node:
json
{
"nodes": [
{
"type": "text",
"id": "Binomial Nomenclature",
"label": "Binomial Nomenclature",
"path": "Binomial Nomenclature"
},
{
"type": "textarea",
"id": "Physical Description",
"label": "Physical Description",
"path": "Physical Description",
"rows": 4
},
{
"type": "select",
"id": "Phylum",
"label": "Phylum",
"path": "Phylum",
"options": {
"source": "formData",
"path": "Phylum",
"labelKey": "Phylum Value",
"valueKey": "Phylum ID"
},
"placeholder": "Choose a phylum..."
}
]
}Here is an interesting set of attributes in options. Let's look at this more closely in the next section.
Selections as Form Data (formData)
We now need to define a list of choices for the Phylum selection. For illustration purposes, we will have only these options:
- Arthropoda
- Chordata
- Mollusca
- Platyhelminthes
- Nematoda
In the previous example, note that we have "source": "formData" under options. formData means that our source is defined in the Form Data JSON. Now, let's say we want to display user-friendly labels, but for the actual value, we want to store a code. So p1 represents Arthropoda, p2 represents Chordata, etc... We will need an array with the key matching labelKey for user-friendly display labels and valueKey for the actual value that we will store.
So here is our Form Data:
json
{
"Phylum": [
{"Phylum ID": "p1", "Phylum Value": "Arthropoda"},
{"Phylum ID": "p2", "Phylum Value": "Chordata"},
{"Phylum ID": "p3", "Phylum Value": "Mollusca"},
{"Phylum ID": "p4", "Phylum Value": "Platyhelminthes"},
{"Phylum ID": "p5", "Phylum Value": "Nematoda"}
]
}Rest of the Inputs
By now you should have a clearer idea of how to use the input types. For a complete list of inputs, check out the node types in the reference section.
With the last input for Population Estimates, your form definition should look like this:
json
{
"nodes": [
{
"type": "text",
"id": "Binomial Nomenclature",
"label": "Binomial Nomenclature",
"path": "Binomial Nomenclature"
},
{
"type": "textarea",
"id": "Physical Description",
"label": "Physical Description",
"path": "Physical Description",
"rows": 4
},
{
"type": "select",
"id": "Phylum",
"label": "Phylum",
"path": "Phylum",
"options": {
"source": "formData",
"path": "Phylum",
"labelKey": "Phylum Value",
"valueKey": "Phylum ID"
},
"placeholder": "Choose a phylum..."
},
{
"type": "number",
"id": "Population Estimates",
"label": "Population Estimates",
"path": "Population Estimates"
}
]
}Validations
If you have been experimenting, you may have noticed that you can upload without entering any input. So let's add some validations to enforce proper data ingestion.
IMPORTANT
By default no validations are performed regardless of the input type and all inputs are optional.
Validations - Make Input Mandatory
Add validations with this structure to make inputs mandatory:
json
{
"type": "text",
"id": "Binomial Nomenclature",
"label": "Binomial Nomenclature",
"path": "Binomial Nomenclature",
"validation": {
"required": true
}
}Check out the complete validation reference here.
