Overview
A field is a property of the entity to be imported. For example, if you are importing Contacts some fields are the "First name", "Last name", "Phone", "Email" and "Country". When defining the fields, it is sufficient to provide only the label. These are enough to get you started.
What about the data type, you may ask. Well, that is not necessary. Everything is treated as a string and you can use transformers and validators to normalize the data and apply some constraints. More on this later.
Let's continue with our example, to import Contacts. Here is a possible definition for fields, without any validators or transformers for now. The example below is enough to allow your users to map data from their CSV and Excel files. The fields will appear in the wizard with the same order as defined in the array below.
1[ 2 { 3 "label": "First name" 4 }, 5 { 6 "label": "Last name" 7 }, 8 { 9 "label": "Phone"10 },11 {12 "label": "Email"13 },14 {15 "label": "Country"16 }17]
By design, importOK tries to match the fields specified in the schema to the columns included in the uploaded file. This is done by calculating the Levenshtein distance between each field and header name, making it ideal to auto-correct typos and align header labels with the actual field name. Having said that, it is still possible to define your own mapping strategy.
label
Description | The field label to be displayed when mapping and reviewing mapped data. |
---|---|
Type | string |
Default | The field name |
description
Description | Further details about the field, that is displayed below the label when mapping. |
---|---|
Type | string |
Default | '' (empty string) |
transformers
Description | Pipe separated transformers i.e. trim|lowercase . They can be provided also as an array i.e. ['trim', 'lowercase'] |
---|---|
Type | string|string[] |
Default | '' (empty string) |
validators
Description | Pipe separated validators i.e. email|required . They can be provided also as an array i.e. ['email', 'required'] |
---|---|
Type | string|string[] |
Default | '' (empty string) |
provider
Description | A data provider to be used to provide suggestions (typeahead). |
---|---|
Type | string |
Default | '' (empty string) |
In the next step we are going to extend the above example to include a few transformers aiming to auto heal the uploaded data, like trimming spaces.