AEM 6.4 has reached the end of extended support and this documentation is no longer updated. For further details, see our technical support periods. Find the supported versions here.
You can use the Form Bridge APIs to open a communication channel between an XFA-based HTML5 forms and your applications. The Form Bridge APIs provides a connect API to create the connection.
The connect API accepts a handler as an argument. After a successful connection is created between XFA-based HTML5 form and Form Bridge, the handle is invoked.
You can use the following sample code to create the connection.
// Example showing how to connect to FormBridge
window.addEventListener("FormBridgeInitialized",
function(event) {
var fb = event.detail.formBridge;
fb.connect(function() {
//use form bridge functions
})
})
Ensure that you create a connection before including the formRuntime.jsp file.
getBridgeVersion()
Returns the version number of the Scripting library
isConnected() Checks if Form State has been initialized
Input: None
Output: True if the XFA Form State has been initialized
Errors: None
connect(handler, context) Makes a connection to FormBridge and executes the function after the connection is made and Form State has been initialized
Input:
Output: None
Error: None
getDataXML(options) Returns the current form data in XML Format
Input:
options: JavaScript Object containing following properties:
Output: None
Error: None
registerConfig(configName, config) Registers user / portal specific configurations with FormBridge. These configurations override the default configurations. The supported configurations are specified in the config section.
Input:
configName: Name of the configuration to override
widgetConfig: Allows the user to override the default widgets in the form with custom widgets. The configuration is overridden as follows:
formBridge.registerConfig(“widgetConfig”:{/*configuration*/})
pagingConfig: Allows the user to override the default behavior of rendering only the first page. The configuration is overridden as follows:
window.formBridge.registerConfig(“pagingConfig”:{pagingDisabled: <true | false>, shrinkPageDisabled: <true | false> }).
LoggingConfig: Allows the user to override the level of logging, disable logging for a category, or whether to display the logs console or send to server. The configuration can be overridden as follows:
formBridge.registerConfig{
"LoggerConfig" : {
{
"on":`<true *| *false>`,
"category":`<array of categories>`,
"level":`<level of categories>`, "
type":`<"console"/"server"/"both">`
}
}
SubmitServiceProxyConfig: Allow the users to register submission and logger proxy services.
window.formBridge.registerConfig("submitServiceProxyConfig",
{
"submitServiceProxy" : "`<submitServiceProxy>`",
"logServiceProxy": "`<logServiceProxy>`",
"submitUrl" : "`<submitUrl>`"
});
config: Value of the configuration
Output: Object containing original value of the configuration in data property.
Error: None
hideFields(fieldArray) Hides the fields whose Som expressions are provided in the fieldArray. Sets the presence property of the specified fields to invisible
Input:
Output: None
Error: None
showFields(fieldArray) Shows the fields whose Som expressions are provided in the fieldArray. Sets the presence property of the provided fields to visible
Input:
Output: None
Error: None
hideSubmitButtons() Hides all the submit buttons in the form
getFormState() Returns the JSON representing the Form State
Input: None
Output: Object containing JSON representing the current Form State in data property.
Error: None
restoreFormState(options) Restores the Form State from the provided JSON state in the options object. The state is applied and success or error handlers are called after the operation is complete
Input:
Options: JavaScript Object containing following properties:
Output: None
Error: None
setFocus (som) Sets focus on the field specified in the Som expression
setFieldValue (som, value) Sets the value of the fields for the given Som expressions
Input:
Output: None
Error: Throws an Exception in the case of an incorrect Som expression
getFieldValue (som) Returns the value of the fields for the given Som expressions
Input: Array containing Som expressions of the fields whose value has to be retrieved
Output: Object containing the result as Array in data property.
Error: None
var a = formBridge.getFieldValue(“xfa.form.form1.Subform1.TextField”);
if(a.errors) {
var err;
while((err = a.getNextMessage()) != null)
alert(a.message)
} else {
alert(a.data[0])
}
getFieldProperties(som, property) Retrieve the list of values for the given property of the fields specified in Som expressions
Input:
Output: Object containing the result as Array in *data *property
Error: None
setFieldProperties(som, property, values) Sets the value of the given property for all fields specified in the Som expressions
Input:
Output: None
Error: None
// Example 1: FormBridge.restoreFormState
function loadFormState() {
var suc = function(obj) {
//success
}
var err = function(obj) {
while(var t = obj.getNextMessage()) {
$("#errorDiv").append("<div>"+t.message+"</div>");
}
}
var _formState = // load form state from storage
formBridge.restoreFormState({success:suc,error:err,formState:_formState}); // not passing a context means that this will be formBridge itself. Validation errors will be checked.
}
//--------------------------------------------------------------------------------------------------
//Example 2: FormBridge.submitForm
function SubmitForm() {
var suc = function(obj) {
var data = obj.data;
// submit the data to a url;
}
var err = function(obj) {
while(var t = obj.getNextMessage()) {
$("#errorDiv").append("<div>"+t.message+"</div>");
}
}
formBridge.submitForm({success:suc,error:err}); // not passing a context means that this will be formBridge itself. Validation errors will be checked.
}