@oneblink/sdk-core
    Preparing search index...

    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"
      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"]

      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

        • OptionalprepareNestedInjectables?: (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.

        • replaceRootInjectables: (
              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.

        • resource: T

          The resource that contains properties that support injection or a string

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

          The form submission data to process

      Returns Map<string, T>