Skip to content

Visual Forms JavaScript API

The Visual Forms JavaScript library allows you to embed a visual PDF form directly on your website so that your users can fill it out and generate a PDF. It doesn’t provide the compliance and audit trail features of data requests, but it provides more flexibility and has many options for customization and styling.

Creates an embedded visual form for filling out PDF templates.

DocSpring.createVisualForm(cssSelector, optionsAndCallbacks);

The form is rendered inline, inside the container element. Visual forms don’t have a modal mode.

ParameterTypeRequiredDescription
cssSelectorstringYesCSS selector for the container element where the form will be rendered
optionsAndCallbacksobjectYesConfiguration options and event callbacks
OptionTypeDescription
templateIdstringYour Template ID
OptionTypeDefaultDescription
templateVersionstringnullThe template version to show and submit, e.g. "1.2.3"
templateDataobjectnullCached template data (alternative to templateId)
defaultFormDataobject{}Default values for fields (can be changed by the user)
staticFormDataobject{}Static values for fields (cannot be changed by the user)
fieldOverridesobject{}Override field properties like hidden or backgroundColor
redirectURLstringnullRedirect to this URL after submitting the form
redirectURLQueryParamsbooleantrueAdd submission_id, template_id, and template_name query params to the redirect URL
waitForPDFbooleantrueSet to false to show the thank-you title as soon as the form is saved, without the PDF processing message. The Download PDF button still appears when the PDF is ready, and the form still waits for the PDF before redirecting
testbooleanfalseCreate a test submission instead of a live submission
focusFirstFieldOnLoadbooleanfalseAutomatically focus the first field when the form loads
showSignatureModalOnFocusbooleanfalseOpen signature modal automatically when signature field is focused
showHeaderbooleantrueShow the form header with navigation buttons
adjustHeaderOnScrollbooleantrueKeep header at top of page when scrolling
showClearButtonbooleantrueShow the “Clear Form” button
showTermsOfServiceLinkbooleantrueShow the terms of service link
skipAgreeToTermsOfServicebooleanfalseSkip the “agree to terms” step
previewModebooleanfalseShow form in preview mode with a single “Close” button
previewModeButtonLabelstring"Close"Label for the preview mode button
termsOfServiceLabelstring"DocSpring Terms of Service"Label for terms of service link
termsOfServiceURLstringDocSpring ToSURL for terms of service
showPdfProcessingSpinnerbooleantrueShow spinner while PDF is processing
downloadButtonLabelstring"Download PDF"Label for the download button
regionstringUSUse a DocSpring region: US or EU
hoststringnullUse one host for both app and API URLs, usually for single-domain enterprise deployments
appHoststringnullOverride the app host used for template data and page images
apiHoststringnullOverride the API host used for submission and polling requests

Use region when your account is in the EU region:

Regional visual form
DocSpring.createVisualForm('.form-container', {
templateId: 'tpl_123456',
region: 'EU'
})

For single-domain enterprise deployments, use host:

Enterprise host
DocSpring.createVisualForm('.form-container', {
templateId: 'tpl_123456',
host: 'https://docspring.example.com'
})

For split-domain deployments, use appHost and apiHost. Existing globals such as DocSpring.region, DocSpring.appHost, DocSpring.apiHost, DocSpring.host, DocSpring.scheme, and DocSpring.port are still supported.

Customize the titles and messages shown in the form. These options can be either a plain string or a function that returns a string.

OptionFunction ArgumentsDescription
pdfProcessingTitletemplate (object)Title when PDF is being processed
pdfProcessingMessagetemplate (object)Message when PDF is being processed
waitingForDataRequestsTitleremainingDataRequestsCount (number), template (object)Title when waiting for data requests
waitingForDataRequestsMessageremainingDataRequestsCount (number), template (object)Message when waiting for data requests
completedTitletemplate (object), downloadURL (string)Title when PDF is ready for download
completedTitleNoDownloadtemplate (object)Title when form is submitted (no download)
pdfProcessedMessagetemplate (object), downloadURL (string)Message when PDF is ready
footerHTMLtemplate (object)Custom HTML for the footer
CallbackParametersDescription
onInitialize-Called when the form has been initialized
onLoad-Called when all form pages have been loaded
onClearForm-Called when the form is cleared
onFieldFocus{ id, name, value }Called when a field gains focus
onFieldBlur{ id, name, value }Called when a field loses focus
onFieldChange{ id, name, value, previousValue }Called when a field value changes
onShowAcceptTerms-Called when showing the “accept terms” screen
onSubmitformData (object)Called when the form is submitted
onSavesubmissionId (string)Called when the submission is saved
onProcessed{ submissionId, downloadURL }Called when the PDF is processed. Not called if the form redirects
onErrorerrorCalled if an error occurs
onPreviewModeButtonClicked-Called when preview mode button is clicked

These global functions allow you to interact with the form. Note that only one DocSpring form can be displayed on a page.

FunctionParametersDescription
DocSpring.clearForm()-Clear all data and reset to defaults
DocSpring.submitForm()-Submit the form (shows validation errors if any)
DocSpring.focusNextField()-Focus the next field
DocSpring.focusField(name_or_id)name_or_id: Field name or numeric IDFocus a specific field
DocSpring.setField(name_or_id, value)name_or_id: Field name or numeric ID
value: Value to set
Set a field’s value
DocSpring.returnToForm()-Return to the form after it has been submitted
Basic visual form
DocSpring.createVisualForm('.form-container', {
templateId: 'tpl_123456'
})
Pre-filled form data
DocSpring.createVisualForm('.form-container', {
templateId: 'tpl_123456',
// Default values (user can change)
defaultFormData: {
customer: {
name: 'John Smith',
}
},
// Static values (user cannot change)
staticFormData: {
invoice_number: 'INV-2024-001',
date: '2024-01-15'
}
})
Advanced configuration
DocSpring.createVisualForm('.form-container', {
templateId: 'tpl_123456',
// Skip terms and auto-focus first field
skipAgreeToTermsOfService: true,
focusFirstFieldOnLoad: true,
// Callbacks
onFieldChange: function(field) {
console.log('Field changed:', field.name, field.value);
},
onSubmit: function(formData) {
console.log('Submitting:', formData);
},
onProcessed: function(data) {
console.log('PDF ready:', data.downloadURL);
// Custom download handling
window.location.href = data.downloadURL;
}
})

If the form has a redirect URL (from the redirectURL option or the template’s settings), it redirects instead, and onProcessed is not called.

Field property overrides
DocSpring.createVisualForm('.form-container', {
templateId: 'tpl_123456',
// Hide certain fields or change properties
fieldOverrides: {
internal_notes: {
hidden: true
},
signature: {
backgroundColor: 'FFFEF0'
}
}
})
Preview mode
DocSpring.createVisualForm('.form-container', {
templateId: 'tpl_123456',
// Show form in preview mode
previewMode: true,
previewModeButtonLabel: 'Close Preview',
// Pre-fill with sample data
staticFormData: {
customer: { name: 'Sample Customer' },
amount: 1000
},
onPreviewModeButtonClicked: function() {
console.log('Preview closed');
// Hide the preview container
}
})

Visual forms support all DocSpring field types:

  • Text fields
  • Number fields
  • Date fields
  • Checkboxes
  • Radio buttons
  • Select dropdowns
  • Signatures
  • Images
  • Combined fields

The visual form can be styled by targeting the following CSS classes:

  • .dsp-formWrapper - Main form container
  • .dsp-fieldWrapper - Field container
  • .dsp-button - Buttons
  • .dsp-primaryButton - Primary buttons
  • .dsp-headerWrapper - Form header
  • .dsp-footerWrapper - Form footer

The visual forms library supports all modern browsers:

  • Chrome 60+
  • Firefox 55+
  • Safari 11+
  • Edge 79+

Older versions of Internet Explorer are not supported.