Target mapping - smbc-digital/form-builder GitHub Wiki

Example JSON:

    {
        "Elements": [
            {
                "Type": "Textbox",
                "Properties":
                {
                    "Label": "Enter your first name",
                    "Name": "firstName",
                    "QuestionId": "first-name",
                    "TargetMapping": "customer.firstname"
                }
            }
        ]
    }

When building elements you have the ability to map the answer to custom properties. To allow for this you can specify a TargetMapping property which will be used to map the answer to. The example above would map the firstName textbox to a Customer object with the firstname property. The ability to map multiple questions to the same field is also posibile. An example below shows a custom mapping.

If no taget mapping is specified the questionId will be used when mapping the value.

Target Mapping EXample:

    {
        "Elements": [
            {
                ...
                "Properties":
                {
                    ...
                    "TargetMapping": "customer.firstname"
                }
            },
            {
                ...
                "Properties":
                {
                    ...
                    "TargetMapping": "customer.lastname"
                }
            },
            {
                ...
                "Properties":
                {
                    ...
                    "TargetMapping": "customer.additionalinfomation"
                }
            },
            {
                ...
                "Properties":
                {
                    ...
                    "TargetMapping": "customer.additionalinfomation"
                }
            },
             {
                ...
                "Properties":
                {
                    ...
                    "TargetMapping": "one.two.three"
                }
            }
        ]
    }

The target mapping above would produce this object

    {
        "customer": {
            "lastname": "",
            "firstname": "",
            "additionalinformation": ""
        },
        "one": {
            "two": {
                "three": ""
            }
        }
    }