Esempi JavaScript

Questi esempi descrivono le proprietà e i metodi supportati in questo ambiente di script.

Riferimento a oggetti

Gli esempi seguenti illustrano diversi modi per fare riferimento a un oggetto.

Quando si accede all'istanza specifica di un oggetto, è necessario conoscere il numero di occorrenze di tale oggetto in cui risiede lo script. Lo script restituisce l'oggetto con lo stesso numero di occorrenze dell'oggetto in cui risiede lo script. Ad esempio, esistono tre pulsanti con lo stesso nome (Button1[0], Button1[1] e Button1[2]) e tre campi testo con lo stesso nome (TF1[0], TF1[1] e TF1[2]). Se lo script su Button1[2] è xfa.host.messageBox(TF1.rawValue), il risultato sarà TF1[2].rawValue e non TF1[0].rawValue.

Script

Accesso alla prima istanza di un campo testo

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

Accesso alla prima istanza di un campo testo

// 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";

Accesso a un campo con accessor

// 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;

Accesso a un sottomodulo con un numero indice

// 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";

Accesso a una proprietà 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; 
        } 
    }

Conteggio dei campi testo di 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; 
}

Accesso ai campi utilizzando nomi oggetti parziali

// 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); 
        } 
    } 
}

Accesso a un valore di un elenco di scelte

// 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;

Accesso a un campo di un sottomodulo

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

Accesso a campi di un sottomodulo

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

Ottenimento dei campi da ogni pagina

// 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"; 
        } 
    } 
}

Creazione di un nodo nel modello dati

Questo esempio illustra come creare o duplicare un nuovo nodo modello dati.

Script

Creazione di un nodo dati

// 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);

Manipolazione delle istanze di un sottomodulo

Questi esempi illustrano diversi modi per aggiungere o rimuovere le istanze di un sottomodulo in fase di esecuzione.

Utilizzare instance manager per modificare le pagine di un modulo con un layout fisso. Ogni pagina è un sottomodulo, pertanto aggiungere o rimuovere un sottomodulo corrisponde ad aggiungere o rimuovere una pagina. Tuttavia, in fase di esecuzione non è possibile modificare il layout di un modulo con un layout fisso. È possibile aggiungere o eliminare istanze in corrispondenza dell'eventoform:ready, ma se lo script è su un evento in fase di esecuzione, come click, non viene eseguita alcuna operazione.

Script

Aggiunta di un'istanza richiamando 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);

Aggiunta di un'istanza richiamando la proprietà 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);

Rimozione di un'istanza

// 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);

Rimozione del sottomodulo principale

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

Impostazione del numero di istanze

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

Inserimento di una nuova istanza sottomodulo

// 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);

Aggiunta e rimozione di un sottomodulo

// 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"; 
}

Ottenimento o impostazione dei valori oggetto

Gli esempi seguenti illustrano diversi modi per ottenere o impostare il valore di un oggetto.

Usi

Script

Utilizzo di 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. 

Utilizzo di value

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

Utilizzo di 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. 

Impostazione del valore di un oggetto dati

// 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;

Impostazione del valore della variabile document

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

Uso dei numeri di pagina e dei conteggi delle pagine

Gli esempi seguenti illustrano diverse modalità di utilizzo dei modelli host e layout per avvalersi dei numeri di pagina e dei conteggi delle pagine.

I modelli host e layout presentano vari metodi e proprietà differenti per l'utilizzo dei numeri di pagina e dei conteggi delle pagine. La scelta delle proprietà e dei metodi da utilizzare dipende dagli effetti dello script e da quando questo viene eseguito.

Molte delle proprietà e dei metodi host non sono disponibili sul server. Utilizzare le proprietà e i metodi host per impostare oppure ottenere i numeri di pagina in fase di esecuzione.

Nessuno dei metodi layout imposta il numero di pagine. Utilizzare i metodi layout per ottenere la pagina corrente in corrispondenza dell'evento layout:ready o per visualizzare i numeri di pagina nella parte inferiore della pagina e il numero di pagine all'apertura di un modulo su un client.

Script

Ottenimento del numero di pagine

// 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. 

Ottenimento del numero di pagine con il metodo 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 dell'impaginazione

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

Ottenimento e impostazione del numero della pagina corrente

// 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). 

Ottenimento del numero di pagine con la proprietà 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. 

Scorrimento del documento verso il basso

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

Scorrimento del documento verso l'alto

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

Concatenazione dei valori dati

Gli esempi seguenti illustrano come concatenare i valori dati in un blocco indirizzi e assicurare che non siano presenti righe vuote.

Usi

Script

Concatenazione dei valori dati

// 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";

Calcolo dei totali

L'esempio seguente illustra come calcolare i totali.

Usi

Proprietà

Metodi

length

rawValue

resolveNodes

Script

Calcolo dei totali

// 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;

Modifica del colore dello sfondo

Gli esempi seguenti illustrano come modificare il colore dello sfondo di un sottomodulo o di campi.

In un modulo con un layout scorrevole, è possibile cambiare il colore dello sfondo dell'intero campo, incluse la didascalia e l'area campo, in fase di esecuzione. Tuttavia, in un modulo con un layout fisso, in fase di esecuzione è possibile cambiare solo il colore dello sfondo dell'area campo.

Script

Modifica del colore dello sfondo di un sottomodulo

// 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"; 
    } 
}

Modifica del colore dello sfondo di 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; 
}

Modifica del colore dello sfondo delle righe di un sottomodulo

// 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";

Compilazione di un elenco a discesa

Gli esempi seguenti illustrano diversi modi per aggiungere o rimuovere voci da un elenco a discesa.

Salvare l'elenco di voci prima di compilare un elenco a discesa in fase di esecuzione; in caso contrario le voci andranno perse. Viene salvato solo il valore dei dati.

Script

Compilazione di un elenco a discesa da un servizio 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); 
}

Cancellazione di un elenco a discesa

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

Compilazione di un elenco a discesa da un file di dati

// 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";

Salvataggio dei valori da un elenco a discesa a un altro 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; 
    } 
}

Accesso a un valore di un elenco a discesa utilizzando la proprietà 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;

Salvataggio di un modulo

Gli esempi seguenti illustrano come esportare dati da un modulo e salvare il modulo.

Usi

Proprietà

Metodi

target

exportData

Script

Esportazione dei dati modulo senza specificare il nome file

// 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. 

Esportazione dei dati modulo utilizzando un nome file

// 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. 

Salvataggio di un modulo

// 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();

Rendere un oggetto visibile o invisibile

L'esempio seguente illustra come rendere un oggetto visibile o invisibile. Se un pulsante di stampa è invisibile, l'utente non può stampare il modulo.

L'evento prePrint si attiva subito prima del rendering del modulo per la stampa. Analogamente, l'evento postPrint si attiva subito dopo la stampa del modulo.

Script

Impostazione di un campo in modo che sia visibile o invisibile

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

Impostazione di un pulsante in modo che sia visibile, ma non stampi

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

Utilizzo dei pulsanti di scelta e delle caselle di controllo

Gli esempi seguenti illustrano come selezionare e deselezionare i pulsanti di scelta e le caselle di controllo.

Usi

Proprietà

Metodi

rawValue

messageBox

resolveNodes

Script

Selezione di un pulsante di scelta

// 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);

Accesso ai pulsanti di scelta

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

Cancellazione di un pulsante di scelta

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

Selezione di una casella di controllo

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

Deselezione di una casella di controllo

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

Determinazione dell'eventuale modifica del modulo

L'esempio seguente illustra come determinare l'eventuale modifica del modulo.

Usi

Proprietà

Metodi

rawValue

messageBox

saveXML

Script

Determinazione dell'eventuale modifica del modulo

// 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."); 
}

Disattivazione di tutti i campi modulo

L'esempio seguente illustra come disattivare tutti i campi del modulo.

Script

Disattivazione di tutti i campi modulo

// 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"; 
} 
}