I have created an XFA form using Adobe Designer (LiveCycle) which utilizes 25 textfields. I am trying to create a 'Redact' button which, when pressed, will iterate through the 25 fields and search for a name in the string value of each field. If the name is found then it replaces the name with "********" using a global RegExp and if not, moves on to the next field. This is what i've come up with so far, but it isn't working. Can anyone help?
var name = nameGlobal.value.toString();
var regExp = new RegExp(name, "gi");
var fields = [
xfa.resolveNode("form1.#subform[3].#subform[4].N_Location.F1.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].N_Witnesses.Notes_2.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].F2.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_4.TextField7").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_5.TextField7").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_6.TextField9").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_7.N_7_2.TextField10").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_7.N_7_4.TextField11").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_7.N_7_6.TextField12").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_7.N_7_8.TextField13").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_7.F4.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F5.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F6.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F20.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.PupilSize.F7.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F8.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F9.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F10.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F11.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.#subform[20].TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_9.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Notes_10.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].F13.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].F14.TextField5").rawValue.toString(),
xfa.resolveNode("form1.#subform[3].#subform[4].Msic_Notes.TextField5").rawValue.toString()
];
for (i = 0; i < fields.length; i++) {
if (fields[i] !== null) {
fields[i] = fields[i].replace(name, "********");
}
}
The main reason why the replace is not working is because toString()
method returns a new string, not a pointer to the value.
You can fix the problem by putting references of the nodes instead of the rawValue string.
Using some old javascript...
var name = nameGlobal.value; // might need to add toString() back
var regExp = new RegExp(name, "gi");
var fields = [xfa.resolveNode("path_to_node")];
for (var i = 0; i < fields.length; i++) {
var rawValue == fields[i];
if (rawValue !== null) {
fields[i].rawValue = rawValue.replace(regExp, "********");
}
}
Using modern javascript... (not sure if supported)
let name = nameGlobal.value; // might need to add toString() back
let regExp = new RegExp(name, "gi");
let fields = [ xfa.resolveNode("path_to_node")];
for (let field of fields) {
let rawValue = field.rawValue
if (!rawValue) { // might need to add the !== null
field.rawValue = rawValue.replace(regExp, "********");
}
}
I hope that I was helpful :)