Defining your schema

In this guide, we'll get you started with a basic field configuration to ensure your desired JSON output is mapped properly according to your data model.

For this example, our first entry containing first_name, last_name, email and phone have been set in our fields configuration. The values entered by your user can be set according to your specified constraints which we will go into detail in the next few steps.

[
{ first_name: 'John', last_name: 'Doe', email: '[email protected]', phone: 5551234567 },
{ first_name: 'Jane', last_name: 'Smith', email: '[email protected]', phone: 4441234567 }
]

With just a few modifications to our sample fields config below, your Importer can easily be mapped to your database.

fields: [
{
label: "First Name",
key: "first_name"
},
{
label: "Last Name",
key: "last_name"
},
{
label: "Email Address",
key: "email",
validator: 'email'
},
{
label: "Phone Number",
key: "phone",
description: "Enter Your 10-digit Phone#"
}
]

With the simple configuration above, your Importer will display as this:

Schema

Let's breakdown the Phone Number column in the Importer:

fields: [
{
label: "Phone Number",
key: "phone",
description: "Enter Your 10-digit Phone#"
}
]

The label is displayed in the table header when entering, editing, and reviewing data

label: "Phone Number"

The JSON key you want to map the data to in the final output

key: "phone"

This is a short description of the field which will be displayed as a tooltip in the header of the associated column

description: "Enter Your 10-digit Phone#"

Using Validators

In order to safeguard the data passed through the Importer is properly validated, we have incorporated an optional validator property on each field and each field can have one or more validators associated with it.

Validators can be set with the following options: required, regex_matches, regex_excludes, required_with, required_with_all, required_without, required_without_all.

If selecting just one validation for your field, your validator object would require the minimal following format:

{
validate: 'required'
}

In this example above, we are using the required validator.

required

The field under this validation must be present in the input data and not empty. A field is considered "empty" if one of the following conditions are true:

  • The value is not provided.
  • The value is an empty string.
  • The value is an uploaded file with no path.

regex_matches

The field under validation must match the given regular expression. In the following example, the submitted entry will be compared against regex /^[\w ]+$/ for validation and will cause an error if data is incorrect.

{
validate: 'regex_matches',
regex: /^[\w ]+$/,
error: 'Must only contain alphanumeric characters or spaces'
}

regex_excludes

The field under validation must not match the given regular expression.

{
validate: 'regex_excludes',
regex: /^[\w ]+$/,
error: 'Cannot contain alphanumeric characters or spaces'
}

required_with

The field under validation must be present and not empty only if any of the other specified fields are present.

{
label: "Last Name",
key: "last_name",
validators: [
{
validate: 'required_with',
fields: ['first_name', 'last_name']
}
]
}

required_with_all

The field under validation must be present and not empty only if all of the other specified fields are present.

required_without

The field under validation must be present and not empty only when any of the other specified fields are not present.

required_without_all

The field under validation must be present and not empty only when all of the other specified fields are not present.

Example

Snippet using multiple validators

validators: [
{
validate: 'regex_matches',
regex: /^[\w ]+$/,
error: 'Must only contain alphanumeric characters or spaces'
},
{
validate: 'required'
},
{
validate: 'required_without',
fields: ['first_name', 'last_name']
}
]