Custom Attachments

Last edit: 

Contributors: 

Custom Attachments are used to add one or more attachments to a Profile, Customization, or Transactable.

Defining

You can enable CustomAttachments by adding a Property with attribute_type set to file, for example:

- name: Agreement
  type: file

Form configuration

The Custom Attachment attribute must be defined in a form in order to whitelist and validate the form request.

...
fields:
  custom_attachments:
    agreement:
      file:
        validation:
          file_content_type: { allow: ['image/jpeg', 'image/png', 'application/pdf'] }
...

Fields

Each attachment supports the following self-descriptive fields:

Field name Type Note
file String File object associated with the custom attachment

Displaying, updating

After setting up attachments as described above, you can further customize them in the markup for the forms:


<label>
  <span>Select file...</span>
  <input accept=".pdf,.jpg,.jpeg,.png" name="{{ form_builder.fields.custom_attachments.agreement.file.name }}" type="file">
</label>

<button>Submit file</button>

{% if form_builder.errors['custom_attachments.agreement.file'] %}
  <p>{{ form_builder.errors['custom_attachments.agreement.file'] }}</p>
{% endif %}

The example above shows the predefined attachment tag.

Using GraphQL to query for CustomAttachment

query test_attachment_query {
  customizations {
    results {
      certificate: custom_attachment(name: "agreement") {
        id
        file_name
      }
    }
  }
}

Questions?

We are always happy to help with any questions you may have. Check out our Help page, or contact us.