Function processInjectablesInCustomResource

  • Process a resource with injectable element values to turn a single resource (could be a single) into multiple resources. e.g. "{ELEMENT:Children|Child_Name} {ELEMENT:Family_Name}" with the following submission data:

    {
    "Family_Name": "Smith",
    "Children": [
    {
    "Child_Name": "John"
    },
    {
    "Child_Name": "Jane"
    }
    ]
    }

    Would result in the following resources:

    • "John Smith"
    • "Jane Smith"

    Example

    const emailAddresses = processInjectablesInCustomResource({
    resource: '{ELEMENT:People|Email_Address}',
    submission: {
    People: [
    {
    Email_Address: 'user@oneblink.io',
    },
    {
    Email_Address: 'admin@oneblink.io',
    },
    ],
    },
    formElements: [
    {
    id: '18dcd3e0-6e2f-462e-803b-e24562d9fa6d',
    type: 'repeatableSet',
    name: 'People',
    label: 'People',
    elements: [
    {
    id: 'd0902113-3f77-4070-adbd-ca3ae95ce091',
    type: 'email',
    name: 'Email_Address',
    label: 'Email_Address',
    },
    ],
    },
    ],
    replaceRootInjectables: (resource, submission, formElements) => {
    const { text } = replaceInjectablesWithElementValues(resource, {
    submission,
    formElements,
    excludeNestedElements: true,
    // other options
    })
    return text
    },
    })
    // emailAddresses === ["user@oneblink.io", "admin@oneblink.io"]

    Returns

    Type Parameters

    • T

    Parameters

    • options: {
          formElements: FormElement[];
          prepareNestedInjectables?: ((resource: T, preparer: ((resourceText: string) => string)) => T);
          replaceRootInjectables: ((resource: T, submission: {
              [name: string]: unknown;
          }, formElements: FormElement[]) => undefined | string | [injectedText: string, resourceKey: string, newResource: T]);
          resource: T;
          submission: {
              [name: string]: unknown;
          };
      }
      • formElements: FormElement[]

        The form elements to process

      • Optional prepareNestedInjectables?: ((resource: T, preparer: ((resourceText: string) => string)) => T)
          • (resource: T, preparer: ((resourceText: string) => string)): T
          • An optional function to replace nested injectables when creating multiple resources from repeatable sets. Only required if the resource param is not a string.

            Returns

            Parameters

            • resource: T

              The current resource that contains properties that support injection or a string

            • preparer: ((resourceText: string) => string)
                • (resourceText: string): string
                • Parameters

                  • resourceText: string

                  Returns string

            Returns T

      • replaceRootInjectables: ((resource: T, submission: {
            [name: string]: unknown;
        }, formElements: FormElement[]) => undefined | string | [injectedText: string, resourceKey: string, newResource: T])
          • (resource: T, submission: {
                [name: string]: unknown;
            }, formElements: FormElement[]): undefined | string | [injectedText: string, resourceKey: string, newResource: T]
          • A function to inject values, this allows custom formatters to be used. Return undefined to prevent the injection from recursively continuing.

            Returns

            Parameters

            • resource: T

              The current resource that contains properties that support injection or a string

            • submission: {
                  [name: string]: unknown;
              }

              The current form submission data to process (may be an entry in a repeatable set)

              • [name: string]: unknown
            • formElements: FormElement[]

              The current form elements to process (may be the elements from a repeatable set)

            Returns undefined | string | [injectedText: string, resourceKey: string, newResource: T]

      • resource: T

        The resource that contains properties that support injection or a string

      • submission: {
            [name: string]: unknown;
        }

        The form submission data to process

        • [name: string]: unknown

    Returns Map<string, T>