Ich hab das Script mal überprüft, das Designer einfügt, um Pflichtfelder zu validieren.
Code: Alles auswählen
Formular1.#variables[0].ColorFieldsValidation - (JavaScript, client)
//+ GENERATED - DO NOT EDIT
//+ Type: ColorFields
//+ MandatoryBorderColor: 16737843
//+ MandatoryBackColor: 16764057
//+ FailedBorderColor: 255
//+ FailedBackColor: 8421631
//+ Color: failed
function InitializeColorFields() {
// Disable Acrobat's field highlighting. The Color
// Failed Fields action takes care of highlighting fields.
if (xfa.host.name == "Acrobat") {
app.runtimeHighlight = false;
}
}
function DoColorFields(oInvalidNode) {
// If this form is running on a client other than Acrobat
// (like on the server) then don't run this script
if (xfa.host.name != "Acrobat") {
return;
}
var sClassName = oInvalidNode.className;
// Only color nodes that are <field>s or <exclGroup>s
// Ignore everything else
if ((sClassName != "field") &&
(sClassName != "exclGroup")) {
return;
}
// If the node is a <field> that is a button or a barcode, then don't
// do any color processing
if (sClassName == "field") {
var sUIClassName = oInvalidNode.ui.oneOfChild.className;
if ((sUIClassName == "barcode") ||
(sUIClassName == "button")) {
return;
}
}
if (oInvalidNode.errorText == "") {
// Validation Succeeded
// Revert the appearance to its original state
var oBorder = sClassName == "field" ? oInvalidNode.ui.oneOfChild.border : oInvalidNode.border;
oBorder.parent.nodes.remove(oBorder);
// Remove the tool tip if it wasn?t originally specified
var sSOM = oInvalidNode.somExpression;
sSOM = sSOM.replace("xfa[0].form[0]", "xfa[0].template[0]");
var oOriginalNode = xfa.resolveNode(sSOM);
var oOriginalAssist = oOriginalNode.assist;
if (!oOriginalAssist.isPropertySpecified("toolTip")) {
var oToolTip = oInvalidNode.assist.toolTip;
oInvalidNode.assist.nodes.remove(oToolTip);
}
}
else {
// Validation Failed
// Show the invalid appearance
var oFailedBorder = sClassName == "field" ? oInvalidNode.ui.oneOfChild.border : oInvalidNode.border;
// Border color
// Show a solid border with square corners
var sBorderColor = "255, 0, 0";
oFailedBorder.presence = "visible";
for (var i = 0; i < 4; i++) {
var oEdge = oFailedBorder.getElement("edge", i);
oEdge.presence = "visible";
oEdge.color.value = sBorderColor;
oEdge.thickness = "2pt";
oEdge.stroke = "solid";
var oCorner = oFailedBorder.getElement("corner", i);
oCorner.presence = "visible";
oCorner.color.value = sBorderColor;
oCorner.thickness = "2pt";
oCorner.stroke = "solid";
oCorner.join = "square";
oCorner.inverted = "0";
oCorner.radius = "0mm";
}
// Background color
// Show a solid fill color
oFailedBorder.fill.color.value = "255, 128, 128";
// The presence of the border must be visible to show the fill.
// Hide the edges when the invalid appearance doesn't include
// changing the border color
if (oFailedBorder.presence != "visible") {
oFailedBorder.presence = "visible";
oFailedBorder.edge.presence = "invisible";
}
// Replace the current fill type with a solid fill
if (oFailedBorder.fill.oneOfChild.className != "solid") {
var oFailedFillType = oFailedBorder.fill.oneOfChild;
oFailedBorder.fill.nodes.remove(oFailedFillType);
var oSolid = xfa.form.createNode("solid", "");
oFailedBorder.fill.nodes.append(oSolid);
}
// Tool Tip
// If a tool tip isn't specified, populate the tool tip
// with the validation message
var oAssist = oInvalidNode.assist;
if (!oAssist.isPropertySpecified("toolTip")) {
var oFailedToolTip = xfa.form.createNode("toolTip");
oAssist.nodes.append(oFailedToolTip);
oAssist.toolTip.value = oInvalidNode.errorText;
}
}
}
//-
Was auffällt ist, dass in Zeile 46 die Variable sSOM von xfa.[0].form[0] auf xfa[0].template[0] geändert wird.
Da das Template ja statisch ist, und sich zur Laufzeit gar nicht verändern kann, hat man natürlich das Problem, dass bei sich wiederholenden Objekten im Template gar keine passende Instanz existiert.
Dadurch ist sSOM null. Da sSOM gleich dannach für die Variable oOriginalNode benutzt wird, die dann per resolveNode aufgelöst wird, scheitert das Ganze dann.
Wenn man diese Zeile auskommentiert oder löscht, funktioniert das Script auch mit sich wiederholenden Objekten.
Code: Alles auswählen
sSOM = sSOM.replace("xfa[0].form[0]", "xfa[0].template[0]");