The FormPage
component wraps the entire functionality of the library and wraps all library functionality,
including form generation and server calls for saving and loading schema data. This component allows
for the rendering of fields from multiple schemas and is fully self-contained, so it can be added to any
React app without the need for additional setup beyond the following required props:
pageName
: A unique name to serve as the CSS id for the wrapper div for all form componentsschemaEndpoint
: An endpoint that stores the JSON schema objects in the formatschema_name.json
dataApiEndpoint
: An endpoint where the form data can be retrieved with HTTPGET
requests and updated with HTTPPOST
requestsschemas
: An object with keys defining the schema groups that will be displayed in the form. Each key references an object with two keys,schema
andincludes
. Theschema
key is the official name of the schema that will be retrieved from theschemaEndpoint
as described above, whileincludes
is an array of the field names from that schema that should be visible in the form. An example is provided below.uiSchema
: The UI schema object that controls the display and type of inputs used on the page. The UI schema is structured as a nested object with top level keys matching the schema names defined inschemas
and each of keys referring to an object keyed by field names for that schema. These field keys reference objects specifying the options for that schema field that will be loaded in when the JSON schema is parsed. The most important option that is shared by all fields isui:component
, which allows for the specification of a different input component type to render the data that the default option for that data type. The UI schema also provides the capability to display an info hover popup to the left of the input component by including some description text with aninfo
key. An example UI schema is also provided below.customInputMap
: An optional object referencing user-defined input components to allow for the usage of inputs from outside the core Formative React repository. This object follows the style of thereactInputMap
file with each string key that can be accessed within the UI schema having a value of a React component type that should be generated for that key. This input map also allows the user to overwrite the base input components such asTextInput
orNumberInput
in cases where they wish to use a different underlying framework such as Material UI instead of React Bootstrap.onError
: A callback for handling error events that occur during API network operations.
<FormPage
schemas={{
"wms-a": {
"schema": "wms",
"include": ["layer", "style"]
},
"comt": {
"schema": "comt",
"include": ["project", "subproject", "model"]
},
}}
.../>
If your use case does not require server-side functionality for schema retrieval and saving or you wish to
provide your own implementation of these network operations, you can use the base Form
component instead
of a FormPage
. The Form
component provides the core schema parsing and form generation functionality
but expects the JSON schema and initial data to be passed in directly as props rather than retrieved
automatically from a server. Note that unlike the FormPage
component, the Form
component only
displays fields from a single JSON schema, and additional schemas will require multiple Form
components. The Form
component takes the following required props:
schema
: A JSON schema object from which the form structure will be generated. Invalid schema formatting will result in an error event being sent in theonError
callback.externalData
: An object keyed by theschema
field names with any initial values that should be presented in the formschemaID
: The name of the schema described inschema
includeFields
: An array of the field names fromschema
that should be visible in the formuiSchema
: The UI schema object that controls the display and type of inputs used on the page. The UI schema is structured as a nested object with top level keys matching the schema names defined inschemas
and each of keys referring to an object keyed by field names for that schema. These field keys reference objects specifying the options for that schema field that will be loaded in when the JSON schema is parsed. The most important option that is shared by all fields isui:component
, which allows for the specification of a different input component type to render the data that the default option for that data type. The UI schema also provides the capability to display an info hover popup to the left of the input component by including some description text with aninfo
key. An example UI schema is also provided below.customInputMap
: An optional object referencing user-defined input components to allow for the usage of inputs from outside the core Formative React repository. This object follows the style of thereactInputMap
file with each string key that can be accessed within the UI schema having a value of a React component type that should be generated for that key. This input map also allows the user to overwrite the base input components such asTextInput
orNumberInput
in cases where they wish to use a different underlying framework such as Material UI instead of React Bootstrap.handleSave
: A callback that recieves updated fields on save events for handling in the parent component.onError
: A callback for handling error events that occur during API network operations.
{
wms: {
opacity: {
"ui:component": "NumberSliderInput"
}
},
"sample-schema": {
bounds: {
info: "The geospatial bounds for the project",
"ui:component": "GeoBoundingBoxInput"
},
description: {
"ui:component": "TextAreaInput",
rows: 4,
info: "A description of the project"
}
}
}
The form generation procedure provides all children within the Form
component with consistently formatted
CSS ids to allow for full custom styling of the form and its fields. All of the id formats are described
below:
All ids in the top level form components are defined based upon the schemaID
passed in as a prop (when
the FormPage
component is used, this is the value of the schema
key defined in the nested schemas
object). For a sample schema named wms
, the following ids would be accessible in CSS:
wms-FORM
: The wrapper div for theForm
component that contains all fields and the form save button.wms-SAVE
: The save button for theForm
component.
All ids at the level of groups of inputs are defined based upon the name of that field group defined in the
JSON schema. For a sample group named general
, the following id is always rendered to the page:
general-INPUTS
: A wrapper div for all inputs within the group, allowing for group-based styles.
Nodes with the following ids are optionally rendered if the JSON schema provides the relevant data:
general-LABEL
: A heading label displayed above the group of inputsgeneral-DESCRIPTION
: A text description of the contents of the group displayed below the list of inputs
All ids at the level of individual inputs are defined based upon the name of that field defined in the
JSON schema (and referenced in other locations such as the includes
list). For a sample input with field
name project
, the following ids are always rendered to the page:
project-GROUP
: The React BootstrapForm.Group
wrapper around the input component and all associated componentsproject
: The input component itselfproject-SAVE
: The save button displayed to the right of the input component that becomes active when the value of the input field is updated
Nodes with the following ids are optionally rendered if the JSON schema and UI schema provide the relevant data:
project-LABEL
: The title label for the fieldproject-DESCRIPTION
: A text description displayed below the fieldproject-INFO
: An optional info hover button that displays additional information about the field