On this page, you will find information about the form’s global variables, properties, methods, and events.
These variables are available globally and can be used directly from the JavaScript editor.
fd is a Form Manager that provides access to all events, containers, controls, fields, validators, and data of the form.
Whenever you want to manipulate your form, you must call the manager first.
// the form is ready
fd.rendered(function() {
// and its fields are available to get/set
fd.field('Title').value = 'New Title';
});
Note
fd is accessible globally on the Preview page, so you can run tests directly from the browser console (F12).
$ allows you to access jQuery library. It can be used to apply direct changes to DOM, hide and show fields, and much more.
// hide fields by CSS class
$('.field-to-hide').hide();
// change input background color
$(fd.field('Field1').$el).find('input').css('background-color', 'red');
Vue is a global Vue object. Allows you to register global components or wait for the next DOM update cycle with Vue.nextTick.
fd has the following properties:
Gets the ID of the submission.
fd.submissionId; // '2021-12-30T13:40:22-4dcdad7b-6fdc-44ab-9789-cfd9118b6780'
Checks if the form is valid or not.
Each time the property is called, it runs validators on all form elements recursively.
Returns true on success. Otherwise, returns false and error messages get displayed.
fd.isValid;
Gets an array of form validators. Can be used to add new ones. These are more complex validators than Field validators and are used to check that multiple fields have appropriate values. If the fields do not match these criteria, the form will not submit.
// return form validators
fd.validators;
// add new form Validator
fd.validators.push({
name: 'MyCustomValidator',
error: 'Age must be 18 or over in order to subscribe',
validate: function(value) {
if (fd.field('Age').value < 18
&& fd.field('PaymentModel').value === 'Subscription')
return false;
return true;
}
});
Gets the logged-in user (for forms that require authenitcation).
fd.account.username; // '[email protected]'
fd has the following methods:
Gets data from all fields on the form. Can be also used to set multiple values at the same time.
// get data as an object
fd.data();
// set field values
fd.data({Field1: value1, Field2: value2});
Exports the current form to a PDF file. Accepts the following arguments:
file – a filename of the file.
options – options for the PDF file, such as paper size, margin, orientation, etc.
fd.exportToPDF('contacts-form', {
paperSize: 'A4',
landscape: false,
multiPage: true
});
Find more about PDF options in How to save form as PDF for printing.
fd has the following events:
Occurs prior to the form creation.
vueConfig passed as an argument to the handler is a configuration of the main vue-component. You can register your own child components. You can read more about it here.
Asynchronous event
Can return a Promise and the corresponding operation will not continue until the promise is resolved.
fd.beforeCreate(function(vueConfig) {
console.log('beforeCreate');
console.log(vueConfig);
});
Occurs as soon as the form is created.
vue passed as an argument to the handler is a Vue instance of the form.
It is also available from fd variable this way: fd._vue
fd.created(function(vue) {
console.log('created');
console.log(vue);
});
Occurs before mounting the vue-component to DOM.
vue passed as an argument to the handler is a Vue instance of the form.
It is also available from fd variable this way: fd._vue
Asynchronous event
Can return a Promise and the corresponding operation will not continue until the promise is resolved.
fd.beforeRender(function(vue) {
console.log('beforeRender');
console.log(vue);
});
Occurs after mounting the vue-component to DOM.
Best place to run your JavaScript since all elements are mounted.
vue passed as an argument to the handler is a Vue instance of the form.
It is also available from fd variable this way: fd._vue
fd.rendered(function(vue) {
console.log('rendered');
console.log(vue);
});
Occurs before submitting the form.
data passed as an argument to the handler is an object representing user’s input.
Keys are internal names of form fields, Values – user’s input:
{
Field1: 'text'
DateTime1: new Date('2017-01-01')
}
Here, you can modify form’s data with code before sending it to the server.
Asynchronous event
Can return a Promise and the corresponding operation will not continue until the promise is resolved.
fd.beforeSave(function(data) {
console.log('beforeSave');
console.log(data);
});
//async check
fd.beforeSave(function(data) {
return $.getJSON('https://mywebservice.contoso.com')
.then(function(result) {
if(result == null){
throw new Error('No results');
}
data.additionalProperties = result;
});
});