Ejemplos de JavaScript

En estos ejemplos se ilustran las propiedades y los métodos compatibles con este entorno de secuencias de comandos.

Referencia a objetos

En estos ejemplos se ilustran varias formas de hacer referencia a un objeto.

Al acceder a una instancia específica de un objeto, debe tener en cuenta el número de incidencia del objeto donde reside la secuencia de comandos. La secuencia de comandos devolverá el objeto con el mismo número de incidencia que el objeto en el que reside la secuencia de comandos. Por ejemplo, supongamos que hay tres botones con el mismo nombre (Button1[0], Button1[1] y Button1[2]) y tres campos de texto con el mismo nombre (TF1[0], TF1[1] y TF1[2]). Si la secuencia de comandos de Button1[2] es xfa.host.messageBox(TF1.rawValue), el resultado será TF1[2].rawValue en lugar de TF1[0].rawValue.

Secuencias de comandos

Acceso a la primera instancia de un campo de texto

// Access a sibling field using the field name. 
// Access the first instance of TextField1.  
TextField1.rawValue = "Hello";

Acceso a la primera instancia de un campo de texto

// Access the first instance of TextField1. When scripting with JavaScript, use 
// xfa.resolveNode to start the search at the top and move down the form  
// hierarchy. 
xfa.resolveNode("TextField1").rawValue = "Hello"; 
xfa.resolveNode("TextField1[0]").rawValue = "Hello";

Acceso a un campo con descriptores de acceso

// When scripting with JavaScript, use the resolveNode() method to access a 
// field with a SOM expression that contains a # or [] operator. When searching 
// with this.resolveNode, the search starts at the current object and moves up 
// the form hierarchy.  
this.resolveNode("Subform2[1].NumericField4").rawValue = 25;

Acceso a un subformulario con un número de índice

// Access a subform with an index number. When using xfa.resolveNode,the search 
// starts at the top of the form hierarchy and moves down.  
var nIndex = 2; 
var sSOM = "Subform2[" + nIndex + "]"; 
var oSubform = xfa.resolveNode(sSOM); 
oSubform.NumericField4.rawValue = "25";

Acceso a una propiedad del campo

// Access a field property using a property name and value. 
// Change the field properties of a specific subform. 
// Use the [] operator to access an object's property. 
var sProperty = "access"; 
var sValue = "readOnly"; 
 
// First, get the subform nodes. 
    var oNodes = Subform2.nodes; 
    var nNodesLength = oNodes.length; 
 
    // Loop through the subform's nodes and look for fields. 
    for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount ++) { 
        // Set the field property. 
        if (oNodes.item(nNodeCount).className == "field") { 
            oNodes.item(nNodeCount)[sProperty] = sValue; 
        } 
    }

Recuento de los campos de texto de un documento

// Count the number of text fields in a document.  
// Get the field containers from each page. 
for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) { 
 
    var oFields = xfa.layout.pageContent(nPageCount, "field"); 
    var nNodesLength = oFields.length; 
    var nCount = 0; 
 
    for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { 
 
        if (oFields.item(nNodeCount).ui.oneOfChild.className == "textEdit") { 
            nCount++; 
        } 
    } 
    TextField1.rawValue = nCount; 
}

Acceso a campos con nombres de objeto parciales

// Access fields using partial object names. 
// Get the field containers from each page. 
for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) { 
 
    var oFields = xfa.layout.pageContent(nPageCount, "field"); 
    var nNodesLength = oFields.length; 
 
    for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { 
        if (oFields.item(nNodeCount).name.substr(0,2) == "Te") { 
            xfa.host.messageBox(oFields.item(nNodeCount).name); 
        } 
    } 
}

Acceso a un valor de una lista de opciones

// Use the newText or prevText property to access the choice list value before 
// or after the value changed. 
// Trigger the script on a change event. 
TextField1.rawValue = xfa.event.prevText; 
TextField2.rawValue = xfa.event.newText;

Acceso a un campo de un subformulario

// Access a field nested inside a sibling subform by prefixing the field name 
// with its parent name. 
Subform2.TextField3.rawValue = "Hello";

Acceso a los campos de un subformulario

// Access the first-level fields nested inside a subform. 
Subform1.resoveNodes("#field[*]")

Obtención de los campos de cada página

// Get the field containers from each page. 
for (var i = 0; i < xfa.host.numPages; i++) { 
 
var oFields = xfa.layout.pageContent(i, "field"); 
var nodesLength = oFields.length; 
 
// Set the access type. 
for (var j = 0; j < nodesLength; j++) { 
 
        var oItem = oFields.item(j); 
 
        if (oItem != this) { 
 
        oItem.access = "readOnly"; 
        } 
    } 
}

Creación de un nodo en el modelo de datos

En este ejemplo se ilustra cómo crear o clonar un nuevo nodo del modelo de datos.

Secuencia de comandos

Creación de un nodo de datos

// Display the number of child nodes under the rootNode (xfa.record). 
// rootNode is the data file's root node. 
xfa.host.messageBox("Initial number of nodes under rootNode: " + xfa.record.nodes.length); 
// Create a node of type dataGroup. 
var oGroupNode = xfa.datasets.createNode("dataGroup", "NewGroupNode"); 
 
// Append the data group node to an existing data model node. 
xfa.record.nodes.append(oGroupNode); 
 
// Display the number of child nodes under rootNode. 
xfa.host.messageBox("Number of nodes under rootNode after first append: " + xfa.record.nodes.length); 
 
// Create a node of type dataValue. 
var oValueNode = xfa.datasets.createNode("dataValue", "NewValueNode"); 
 
// Set the value of the new data value node. 
oValueNode.value = "The item value"; 
 
// Append the data value node to the data group created above. 
xfa.record.NewGroupNode.nodes.append(oValueNode); 
 
// Get the value from the data model. 
TextField1.rawValue = xfa.record.NewGroupNode.NewValueNode.value; 
 
// Append a cloned data group node. 
xfa.record.nodes.append(xfa.record.NewGroupNode.clone(1)); 
 
// Display the number of child nodes under rootNode. 
xfa.host.messageBox("Number of nodes under rootNode after appending clone: " + xfa.record.nodes.length); 
 
// Set the value of the new data value node. 
xfa.resolveNode("xfa.record.NewGroupNode[1].NewValueNode").value = "The clone value"; 
 
// Get the value of the cloned data value node. 
TextField2.rawValue = xfa.resolveNode("xfa.record.NewGroupNode[1].NewValueNode").value; 
 
// Remove the cloned data group from the node list. 
var oRemoveNode = xfa.resolveNode("xfa.record.NewGroupNode[1]"); 
xfa.record.nodes.remove(oRemoveNode); 
 
// Display the number of child nodes under rootNode. 
xfa.host.messageBox("Number of nodes under rootNode once clone node removed: " + xfa.record.nodes.length);

Manipulación de instancias de un subformulario

En estos ejemplos se ilustran varias formas de agregar o quitar instancias de un subformulario en tiempo de ejecución.

Utilice instance manager para manipular las páginas de un formulario con una presentación fija. Cada página es un subformulario; por lo tanto, agregar o quitar un subformulario es como agregar o quitar una página. Sin embargo, en tiempo de ejecución, no se puede cambiar la presentación de un formulario con una presentación fija. Puede agregar y eliminar instancias en el suceso form:ready; sin embargo, si la secuencia de comandos se encuentra en un suceso en tiempo de ejecución, por ejemplo click, no sucederá nada.

Secuencias de comandos

Adición de una instancia invocando instance manager

// Add an instance of a subform by using the underscore syntax to invoke the 
// instance manager directly. 
// Forms rendered in a web browser do not support the underscore syntax. 
// However, the underscore syntax is supported if the script runs at the 
// server. 
_Subform2.addInstance(1);

Adición de una instancia invocando la propiedad instanceManager

// Add an instance of a subform by invoking the instanceManager property. Be 
// careful to ensure that adding a subform will not violate the max occur 
// value. 
Subform2.instanceManager.addInstance(1);

Eliminación de una instancia

// Remove an instance of a subform. Set the min occur value only if removing an 
// instance will violate it. For example, set the min occur to 0 if you want to 
// remove the last, or the only, instance of a subform.  
// Forms rendered in a web browser do not support the underscore syntax. 
// However, the underscore syntax is supported if the script runs at the 
// server.  
Subform2.occur.min = "0"; 
_Subform2.removeInstance(0);

Eliminación del subformulario principal

// Remove the parent subform. 
parent.occur.min = "0"; 
parent.instanceManager.removeInstance(parent.index);

Definición del número de instancias

// Set the number of instances of a subform. 
var oSubform = xfa.resolveNode("Subform2"); 
oSubform.instanceManager.setInstances(5);

Inserción de una nueva instancia de subformulario

// Insert a new subform instance. This script will not work with a static form. 
// The script is invoked by a button, named Insert Subform, that is nested 
// inside a repeating subform. The new subform is inserted below the current 
// subform.  
var oSubform = this.resolveNode("Subform2"); 
var oNewInstance = oSubform.instanceManager.addInstance(1); 
var nIndexFrom = oNewInstance.index; 
var nIndexTo = this.parent.index + 1; 
// Invoke the instanceManager to insert the subform below the current one. 
oSubform.instanceManager.moveInstance(nIndexFrom, nIndexTo);

Adición y eliminación de un subformulario

// Invoke the instance manager to add and remove the comments subform. 
if (fComments.value == "0") { 
// In this example, fComments is a document variable used as a flag. 
// The fComments variable equals 1 when the comments subform is displayed. 
_comments.setInstance(1);  
// Add the comments subform. Change the button's caption. 
this.resolveNode("caption.value.#text").value = "Clear Comments";  
// Set the flag value. 
fComments.value = "1";  
} 
else { 
// Remove the comments subform. 
_comments.setInstance(0);  
// Change the button's caption. 
this.resolveNode("caption.value.#text").value = "Add Comments";  
// Reset the flag value. 
fComments.value = "0"; 
}

Obtención o definición de valores de objeto

En estos ejemplos se ilustran varias formas de obtener o definir un valor para un objeto.

Usos

Secuencias de comandos

Uso de rawValue

// Use the rawValue property to set and get a field's raw value. 
TextField1.rawValue = "K1V1W3"; // Set the field's raw value. 
TextField2.rawValue = TextField1.rawValue // Get the field's raw value. 

Uso de value

// Use the value property to set and get the field's raw value. 
TextField1.rawValue = "k1V1W3"; 
TextField2.rawValue = TextField1.value.oneOfChild.value

Uso de formattedValue

// Use the formattedValue property to set and get the field's formatted value. 
// Use the value property to set and get an object's value (picture). 
TextField1.rawValue = "K1V1W3"; // Set the field's raw value. 
TextField1.format.picture.value = "A9A 9A9"; // Set the field's display picture format. 
TextField2.rawValue = TextField1.formattedValue; // Get the field's formatted value. 

Definición del valor del objeto de datos

// Use the value property to set and get a data object's value. 
// In this script, groupNode is a data group and addressL1 is a data value in 
// the data file. 
TextField1.rawValue = xfa.record.groupNode.address.line1.value;

Definición del valor de la variable de documento

// Use the value property to set and get the document variable's value. 
TextField1.rawValue = docVar.value;

Trabajo con números de página y número de páginas

En estos ejemplos se ilustran varias formas de utilizar los modelos de host y presentación para trabajar con números de página y número de páginas.

Los modelos de host y presentación tienen varias propiedades y métodos diferentes para trabajar con números de página y número de páginas. Las propiedades y los métodos que se deben usar dependen de la acción de la secuencia de comandos y cuándo se ejecute.

Muchos de los métodos y las propiedades host no están disponibles en el servidor. Utilice los métodos y las propiedades host para definir u obtener números de página en tiempo de ejecución.

Ninguno de los métodos de presentación define el número de página. Utilice los métodos de presentación para obtener la página actual en layout:ready o para mostrar los números de página de la parte inferior de la página y ver el número de página al abrir un formulario en un cliente.

Secuencias de comandos

Obtención del número de página

// Use the page layout methods to get the current page number. 
TextField1.rawValue = xfa.layout.page(this); // 1-based. 
TextField2.rawValue = xfa.layout.absPage(this); // 0-based. 

Obtención del número de páginas mediante el método pageCount

// Use the layout pageCount methods to get the number of pages in a document. 
TextField1.rawValue = xfa.layout.pageCount(); // Get the logical number of pages. 
TextField2.rawValue = xfa.layout.absPageCount(); // Get the physical number of pages. 

Formato de la paginación

// Use the layout page and pageCount methods to format the pagination. 
TextField1.rawValue = "Page " + xfa.layout.page(this) + " of " + xfa.layout.pageCount();

Obtención y definición del número de página actual

// Use the host currentPage property to get and set the current page number at // run time. 
// This script cannot be used during a layout:ready, form:ready, or initialize // event. However, it will work if the script is on a button. 
xfa.host.currentPage = 1; // Go to page 2 (0-based). 

Obtención del número de páginas mediante la propiedad numPages

// Use the host numPages property to get the number of pages in a document. 
TextField1.rawValue = xfa.host.numPages; // Get the number of pages. 

Desplazamiento hacia abajo en un documento

// Use the host pageDown() method to navigate through a document. 
xfa.host.pageDown(); // Go to the next page. 

Desplazamiento hacia arriba en un documento

// Use the host pageUp() method to navigate through a document. 
xfa.host.pageUp(); // Go to the previous page. 

Concatenación de valores de datos

En este ejemplo se ilustra cómo concatenar valores de datos en un bloque de dirección y asegurarse de que no hay líneas en blanco.

Usos

Propiedades

Métodos

multiLine

oneOfChild

rawValue

value

record

Secuencia de comandos

Concatenación de valores de datos

// Get the values from the data model. 
var sName = xfa.record.groupNode.address.line1.value; 
var sPostbox = xfa.record.groupNode.address.line2.value; 
var sStreet = xfa.record.groupNode.address.line3.value; 
var sCity = xfa.record.groupNode.address.line4.value; 
var sRegion = xfa.record.groupNode.address.line5.value; 
var sCountry = xfa.record.groupNode.address.line6.value; 
var sPostcode = xfa.record.groupNode.address.line7.value; 
var addressArray = new Array(sName,sPostbox,sStreet,sCity,sRegion,sCountry,sPostcode); 
 
var sAddressBlock = ""; 
 
// Don't display the postbox if the value is not provided. 
if (addressArray[1] == null) { 
        sAddressBlock = addressArray[0] + "\n" + addressArray[2] + "\n" + addressArray[3] + "\n"; 
} else { 
        sAddressBlock = addressArray[0] + "\n" + addressArray[1] + "\n" + addressArray[3] + "\n"; 
} 
 
// Do not display the region if the value is not provided.  
if (addressArray[4] == null) { 
sAddressBlock = sAddressBlock + addressArray[5] + " " + addressArray[6]; 
} else { 
sAddressBlock = sAddressBlock + addressArray[4] + ", " + addressArray[5] + " " + addressArray[6]; 
} 
TextField2.rawValue = sAddressBlock; 
// Make sure the field is set to display a multiple line value. To set the 
// multiLine property programmatically, add the following line: 
        TextField2.ui.oneOfChild.multiLine = "1";

Cálculo de totales

En este ejemplo se ilustra cómo calcular totales.

Usos

Propiedades

Métodos

length

rawValue

resolveNodes

Secuencia de comandos

Cálculo de totales

// Access a field in a repeating subform by looping through the node list. 
var oFields = xfa.resolveNodes("Subform2[*].NumericField4"); 
var nNodesLength = oFields.length; 
var nSum = 0; 
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { 
    nSum += oFields.item(nNodeCount).rawValue; 
} 
TextField1.rawValue = nSum;

Cambio del color de fondo

En estos ejemplos se ilustra cómo cambiar el color de fondo de un subformulario o de los campos.

En un formulario con una presentación flexible, puede cambiar el color de fondo de todo el campo, incluidos el rótulo y el área del campo, en tiempo de ejecución. Sin embargo, en un formulario con una presentación fija, solo se puede cambiar el color de fondo del área del campo en tiempo de ejecución.

Secuencias de comandos

Cambio del color de fondo de un subformulario

// Alternate the background color of a repeating subform. 
var oNodes = xfa.resolveNodes("Subform2[*]"); 
var nNodesLength = oNodes.length; 
 
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { 
    if (oNodes.item(nNodeCount).index%2 != 0) { 
        oNodes.item(nNodeCount).border.fill.color.value = "200,200,250"; 
    } else { 
        oNodes.item(nNodeCount).border.fill.color.value = "200,150,250"; 
    } 
}

Cambio del color de fondo de un campo

// Alternate the background color of the NumericField4 field. 
// Before running this script, set a background color or set the 
// border.fill.presence property to visible. 
var oNodes = xfa.resolveNodes("Subform2[*]"); 
var nNodesLength = oNodes.length; 
var sFillColor; 
 
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { 
 
    if (oNodes.item(nNodeCount).index%2 != 0) { 
        sFillColor = "200,200,250"; 
 
    } else { 
        sFillColor = "200,150,250"; 
 
    } 
    oNodes.item(nNodeCount).NumericField4.fillColor = sFillColor; 
}

Cambio del color de fondo de filas de un subformulario

// Reset the fields of the current subform. 
var dString = "xfa.form.form1.dtls[" + this.parent.index + "]"; 
var oDetails = xfa.form.resolveNode(dString); 
var sDtlFields; 
 
// Build the string of field names to reset. 
for (var i = 0; i < oDetails.nodes.length; i++) { 
    sDtlFields = sDtlFields + "," + dString + "." + oDetails.nodes.item(i).name; 
} 
// Pass the string variable as a parameter. 
xfa.host.resetData(sDtlFields); OR  
// Alternate the background color of the repeating rows. 
if (this.index%2 != 0)  this.border.fill.color.value = "255,255,255"; else  this.border.fill.color.value = "201,201,146";

Rellenado de una lista desplegable

En estos ejemplos se ilustran varias formas de agregar o quitar elementos en una lista desplegable.

Guarde la lista de elementos antes de llenar una lista desplegable en tiempo de ejecución; de lo contrario, se perderán los elementos. Solo se guarda el valor en los datos.

Secuencias de comandos

Rellenado de una lista desplegable desde un servicio Web

// Populate the drop-down list with values from a web service. 
// The web service used in this example is fictional.  
SOAP.wireDump = false; 
var oListURL = "http://www.webservice.net/wsdl/query.wsdl"; 
var e; 
try 
{ 
    xfa.host.messageBox("Starting list retrieval."); 
     
    var service = SOAP.connect(oListURL); 
 
    if(typeof service != "object") { 
        xfa.host.messageBox("Couldn't get List object."); 
    } 
    if(service.getAllServiceNames == "undefined") { 
        xfa.host.messageBox("Couldn't get getAllServiceNames Call."); 
        } 
     
    // Start the query 
    var oItems = service.getAllServiceNames(); 
    if(oItems == null) { 
        xfa.host.messageBox("List empty."); 
        } 
var nCount = 0; 
    var nLimit = 10; 
     
    for(var nItemCount in oItems)  
    { 
        for(var nItemNode in oItems[nItemCount]) 
        { 
            if (nItemNode == "name") 
                DropDownList1.addItem(oItems[nItemCount][nItemNode]); 
        } 
        if (++nCount >= nLimit) 
            break; 
    } 
} 
catch(e) 
{ 
    xfa.host.messageBox("Problem with list Call: " + e); 
}

Vaciar una lista desplegable

// Clear the items in a drop-down list. 
DropDownList1.clearItems();

Rellenado de una lista desplegable desde un archivo de datos

// Populate the drop-down list with values from a data file. 
var oItems = xfa.resolveNode("xfa.record.groupNode.list"); 
var nItemsLength = oItems.nodes.length; 
 
for (var nItemCount = 0; nItemCount < nItemsLength; nItemCount++) { 
    DropDownList1.addItem(oItems.nodes.item(nItemCount).value); 
} 
DropDownList1.rawValue = "Second item in list";

Guardar los valores de una lista desplegable en otro campo

// Access the items in a drop-down list box and save their values in a separate 
// field. 
var oItems = xfa.resolveNode("DropDownList1.#items"); 
var nItemsLength = oItems.nodes.length; 
 
for (nItemCount = 0; nItemCount < nItemsLength; nItemCount++){ 
 
    if (TextField2.rawValue == null) { 
        TextField2.rawValue = oItems.nodes.item(nItemCount).value; 
    } else { 
        TextField2.rawValue = TextField2.rawValue + "\n" + oItems.nodes.item(nItemCount).value; 
    } 
}

Acceso a un valor de lista desplegable mediante las propiedades newText o prevText

// Use the newText or prevText properties to access a drop-down list value 
// before or after the value changes. 
// Execute the script on a change event. 
TextField1.rawValue = xfa.event.prevText; 
TextField2.rawValue = xfa.event.newText;

Guardado de un formulario

En estos ejemplos se ilustra cómo exportar datos de un formulario y guardar un formulario.

Usos

Propiedades

Métodos

target

exportData

Secuencias de comandos

Exportación de datos de formulario sin especificar un nombre de archivo

// Export a form's data without specifying a file name. The end user is 
// prompted to provide the file name. 
xfa.host.exportData();      // Will generate data in XDP format. 
xfa.host.exportData("", 0); // Will generate data in XML format. 

Exportación de datos de formulario con un nombre de archivo

// If you specify a file name, the script must run on a certified form. 
xfa.host.exportData("filename.xdp");    // Will generate data in XDP format. 
xfa.host.exportData("filename.xml", 0); // Will generate data in XML format. 

Guardado de un formulario

// Saving the form is done at the application level, so you need to invoke the 
// Acrobat app model. 
App.executeMenuItem("SaveAs"); // The end user will be prompted to specify a 
// file name.  
// However, you must save the form silently if the form needs to be certified 
// and the certificate must be trusted for privileged JavaScript. 
var mydoc = event.target; 
mydoc.saveAs();

Conversión de un objeto en visible o invisible

En este ejemplo se ilustra cómo hacer visible o invisible un objeto. Si un botón de impresión es invisible, el usuario no podrá imprimir el formulario.

El suceso prePrint se desencadena inmediatamente antes de que el formulario se procese para impresión. De la misma manera, el suceso postPrint se desencadena inmediatamente después de que se imprima el formulario.

Usos

Propiedades

presence

relevant

Secuencias de comandos

Definición de un campo para que sea visible o invisible

// If a field is visible, make it invisible and vice versa. 
if(Field1.presence == "visible") 
{ 
    Field1.presence = "invisible"; 
} 
else 
{ 
    Field1.presence = "visible"; 
}

Definición de un botón para que sea visible pero no de impresión

// Set a button to be visible but non-printing at design time.  
Button1.relevant="-print"

Uso de botones de radio y casillas de verificación

En estos ejemplos se ilustra cómo activar y desactivar botones de radio y casillas de verificación.

Usos

Propiedades

Métodos

rawValue

messageBox

resolveNodes

Secuencias de comandos

Activación de un botón de radio

// Select the first radio button. 
RadioButtonList.rawValue = '1'; 
xfa.host.messageBox('Value of RadioButtonList: ' + RadioButtonList.rawValue); 
 
// Select the second radio button. 
RadioButtonList.rawValue = '2'; 
xfa.host.messageBox('Value of RadioButtonList: ' + RadioButtonList.rawValue);

Acceso a botones de radio

// Access the radio buttons. 
RadioButtonList.resolveNodes("#field[*]")

Desactivación de un botón de radio

// Clear a RadioButtonList value. Any invalid value will clear the list. 
RadioButtonList.rawValue = '3'; 
xfa.host.messageBox('Value of RadioButtonList: ' + RadioButtonList.rawValue);

Activación de una casilla de verificación

// Select a check box. 
CheckBox1.rawValue = 1; 
xfa.host.messageBox('Value of checkbox: ' + CheckBox1.rawValue);

Desactivación de una casilla de verificación

// Deselect a check box. 
CheckBox1.rawValue = 0; 
xfa.host.messageBox('Value of checkbox: ' + CheckBox1.rawValue);

Determinación de los cambios de un formulario

En este ejemplo se ilustra cómo determinar si un formulario ha cambiado.

Usos

Propiedades

Métodos

rawValue

messageBox

saveXML

Secuencia de comandos

Determinación de los cambios de un formulario

// Save a copy of the original XML file. 
var sOriginalXML = xfa.data.saveXML(); 
 
// Change the form data. 
TextField1.rawValue = "changed"; 
 
// Determine whether the form data has changed. 
if(sOriginalXML == xfa.data.saveXML()) 
{ 
    xfa.host.messageBox("Form has not changed."); 
} 
else 
{ 
        xfa.host.messageBox("Form has changed."); 
}

Desactivación de todos los campos de formulario

En este ejemplo se ilustra cómo desactivar todos los campos de un formulario.

Secuencia de comandos

Desactivación de todos los campos de formulario

// Get the field containers from each page. 
for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) { 
var oFields = xfa.layout.pageContent(nPageCount, "field"); 
var nNodesLength = oFields.length; 
 
// Set the field property. 
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { 
oFields.item(nNodeCount).access = "readOnly"; 
} 
}