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);
// or
DocSpring.createVisualForm(optionsAndCallbacks);
ParameterTypeRequiredDescription
cssSelectorstringNoCSS selector for the container element where the form will be rendered. If omitted, the form opens as a modal overlay
optionsAndCallbacksobjectYesConfiguration options and event callbacks
OptionTypeDescription
templateIdstringYour Template ID
templateVersionstringTemplate version to use (defaults to “latest”)
OptionTypeDefaultDescription
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
waitForPDFbooleantrueIf redirectURL is provided, wait for PDF processing before redirecting
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 ToS"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

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
onClearForm-Called when the form is cleared
onFieldFocus{ id, name, value, containerElement, inputElement }Called when a field gains focus
onFieldBlur{ id, name, value, containerElement, inputElement }Called when a field loses focus
onFieldChange{ event, id, name, value, previousValue, containerElement, inputElement }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
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
Basic visual form
DocSpring.createVisualForm('.form-container', {
templateId: 'tpl_123456'
})
Visual form as modal
// Omit the CSS selector to open as a modal
DocSpring.createVisualForm({
templateId: 'tpl_123456',
templateVersion: '2'
})
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({
templateId: 'tpl_123456',
// Skip terms and auto-focus first field
skipAgreeToTermsOfService: true,
focusFirstFieldOnLoad: true,
// Custom messages
pdfProcessingTitle: 'Generating Your Document...',
completedTitle: function(template) {
return 'Your ' + template.name + ' is Ready!';
},
// Redirect after completion
redirectURL: 'https://example.com/thank-you',
waitForPDF: false,
// 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;
}
})
Field property overrides
DocSpring.createVisualForm({
templateId: 'tpl_123456',
// Hide certain fields or change properties
fieldOverrides: {
internal_notes: {
hidden: true
},
signature: {
backgroundColor: 'FFFEF0'
}
}
})
Preview mode
DocSpring.createVisualForm({
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
}
})
Custom footer buttons
DocSpring.createVisualForm({
templateId: 'tpl_123456',
footerHTML: function(template) {
return '<div class="dsp-footerLeft">' +
'<button class="dsp-button dsp-primary" onclick="customSave()">Save Draft</button>' +
'</div>' +
'<div class="dsp-footerRight">' +
'<button class="dsp-button" onclick="customCancel()">Cancel</button>' +
'</div>';
}
})

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-form - Main form container
  • .dsp-field - Field container
  • .dsp-button - Buttons
  • .dsp-primary - Primary buttons
  • .dsp-header - Form header
  • .dsp-footer - 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.