To adjust for the timing of the SC call, rather than being run on document load, make it a function and call it onsuccess of the SC element:
<script>
function makeform() {
// your javascript here
$( window ).on( "orientationchange", function( event ) {
location.reload(true);
});
if (window.DocSpring) {
DocSpring.createVisualForm('.fa-form', {
templateId: dmx.parse('query.template_id'),
// When false, we show the confirmation message immediately.
// (This is always false if the template has "private submissions"
// and the user is not signed in.)
waitForPDF: true,
// You can also pass the cached template data directly,
// which will make the page load faster.
// (If you use templateId, we make an API request to fetch the template data.)
// templateData: { id: '', name: '', ... },
// Set some default values for fields (can be changed by the user.)
// This will override any default values set in the template editor.
// You must provide structured JSON data that matches your API schema, e.g.:
defaultFormData: { practitiioner_name: dmx.parse('query.practiceName'), pract_address_1: dmx.parse('query.address'), pract_city: dmx.parse('query.city'), pract_state: dmx.parse('query.state'), pract_zip: dmx.parse('query.zip'), pract_email: dmx.parse('query.email'), phone: dmx.parse('query.phone'), facility: dmx.parse('query.company'), pract_address_2: dmx.parse('query.address2'), shipping_contact: dmx.parse('query.shipping_contact'), shipping_address_1: dmx.parse('query.shipping_address_1'), shipping_address_2: dmx.parse('query.shipping_address_2'), shipping_city: dmx.parse('query.shipping_city'), shipping_state: dmx.parse('query.shipping_state'), shipping_zip: dmx.parse('query.shipping_zip'), billing_contact: dmx.parse('query.billing_contact'), billing_address: dmx.parse('query.billing_address'),billing_city: dmx.parse('query.billing_city'),billing_state: dmx.parse('query.billing_state'),billing_zip: dmx.parse('query.billing_zip'), billing_facility: dmx.parse('query.billing_facility'), transfer_pattern: dmx.parse('query.transfer_pattern'), transfer_option: dmx.parse('query.transfer_option'), ptid: dmx.parse('query.ptid')},
// override the value for transfer patterns
fieldOverrides: { transfer_option: { optionList: dmx.parse('query.practiceName') }},
//fieldOverrides: { transfer_option: { optionList: dmx.parse('conn_transferPaper.data.transferPattern') }},
// Set some static values for fields (cannot be changed by the user.)
// staticFormData: { person: { first_name: 'Harry' } },
// Overrides the template's redirect URL
// redirectURL: brace-order-step3.asp,
// As soon as the form is loaded, automatically focus the first field.
// (Default: The user must click the "Start" button to focus the first field.)
// focusFirstFieldOnLoad: true,
// By default, the user must click the signature field to open the
// signature modal. Set the showSignatureModalOnFocus option to true
// if you want to open the signature modal automatically when a
// signature field is focussed (i.e. with the "Next" button or the Tab key).
// NOTE: It is important that the user can read the document before signing,
// and that they are aware of the location of their signature.
// The default behavior is much better for compliance reasons,
// because the user can view the document before they sign.
// However, this option might be useful if you want to streamline an
// internal document workflow.
showSignatureModalOnFocus: true,
// Customize the header titles, messages, and buttons.
// (Titles and messages can be HTML strings, or functions that return HTML.)
// ------------------------------------------------------------------------------
// Hide the header (if you need to build your own UI)
// showHeader: false,
// Adjust the header position on scroll, to keep it at the top of the page.
// Set this to false if this is causing problems for your implementation.
adjustHeaderOnScroll: false,
// Hide the "clear form" button
// showClearButton: false,
// Don't show the "agree to terms of service" link
showTermsOfServiceLink: false,
// Customize the terms of service link. (Default: DocSpring ToS)
// termsOfServiceLabel: 'YourCompany ToS',
// termsOfServiceURL: 'http://your-company.com/tos',
// pdfProcessingTitle: (template) =>
// 'Processing Document...',
// pdfProcessingMessage: (template) =>
// 'Please wait a few moments while we generate your PDF...',
// showPdfProcessingSpinner: false,
// waitingForDataRequestsTitle: (remainingDataRequestsCount, template) =>
// `Thank you for filling out ${template.name}!`
// waitingForDataRequestsMessage: (remainingDataRequestsCount, template) =>
// 'The PDF will be generated once everyone has filled out and signed the document.',
// completedTitle: (template, downloadURL) =>
// `Thank you for filling out ${template.name}!`,
// completedTitleNoDownload: (template, downloadURL) =>
// `Thank you for filling out ${template.name}!`,
// pdfProcessedMessage: (template, downloadURL) =>
// 'Click the "Download PDF" button to download your signed PDF.',
// downloadButtonLabel: 'Download PDF',
// remove the agreement button/request
skipAgreeToTermsOfService: true,
// Callbacks:
// ------------------------------------------------------------------------------
onClearForm: function() {
console.log('[Callback] Form was cleared');
},
onFieldFocus: function(field) {
// id: number,
// name: string,
// value: any,
// containerElement: ?HTMLDivElement,
// inputElement: ?HTMLInputElement,
console.log('[Callback] Focussed field:', field.name);
},
onFieldBlur: function(field) {
// id: number,
// name: string,
// value: any,
// containerElement: ?HTMLDivElement,
// inputElement: ?HTMLInputElement,
console.log('[Callback] Field lost focus:', field.name);
},
onFieldChange: function(field) {
// event: MouseEvent | KeyboardEvent | Touch,
// id: number,
// name: string,
// previousValue: any,
// value: any,
// containerElement: ?HTMLDivElement,
// inputElement: ?HTMLInputElement,
var name = field.name,
value = field.value,
previousValue = field.previousValue;
console.log('[Callback] Changed field value.', {
name: name,
value: value,
previousValue: previousValue
});
},
onShowAcceptTerms: function() {
console.log('[Callback] Showing "accept terms"');
},
onSubmit: function(formData) {
console.log('[Callback] Form was submitted. Data:', formData);
},
onSave: function (submissionId) {
console.log('[Callback] Submission was saved:', submissionId);
},
onProcessed: function(data) {
// submissionId: string
// downloadURL: string
console.log('[Callback] PDF was generated. Download at:', data.downloadURL);
},
onError: function(error) {
console.log('[Callback] Error:', error);
}
});
}
}
</script>
and add onsuccess="makeform()"
to the SC element