Javascipt to abort code and return to dialog box
Hello,
I am working on automating and preparing a form for digital signature. For prior military, I am referring to an nonjudicial punishment form. The form will be passed back and forth between a commander and a service member and they will add their intitials next options and then digitally sign. I have added a javascript code to execute onblur when the digital signature field is pressed. A dialog box appears and has the commander type his/her initials into one of two options. (I realize that I could use a radio button and it would slove my problems, but its the military and we require physically typing initials into the box). After the commander presses OK, a second window for the digital signature appears. A second javascript is then executed upon signature (from the signed tab) that places the date and time into particular readonly fields in certain blocks on the form (again I realize the digital signature has this information but this is the military and if the block isn't completed the form isn't legally sufficient).
What I am trying to do is create an alternative to a radio button with the text fields in the dialog box. I have written code in the onblur to ensure that only one of the fields has text in it (typing text in 1 field clears the other). Where I am running into trouble is ensuring that at least one of the blocks contains initials. I can't have the commander digitally sign if he/she doesn't add intitials to one of the blocks. I have an if statement after OK is pressed that will check to make sure that both variables are not empty. What I want to do is stop the script prevent it from running the digital signature window and either "cancel out" forcing the commander to click the digital signature field again (or better) go back to the dialog box for the commander to enter his/her initials.
I have seen a prior post where this problem was circumented by adding a button and hiding the digital signature until the "validation" is performed, but the form doesn't provide the space for a button nor can I add buttons to the form.
Most appreciated if someone knows of a viable option.
PS I am an JAG and not a programmer by trade so forgive me if my question is impossible based upon how the code is executing or if it is something a child should know.
Thanks,
Mike
My code is:
var Offer =
{
result:"cancel",
DoDialog: function(){return app.execDialog(this);},
strOpt1:"",
strOpt2:"",
initialize: function(dialog)
{
var dlgInit =
{
"Opt1": this.strOpt1,
"Opt2": this.strOpt2,
};
dialog.load(dlgInit);
},
commit: function(dialog)
{
var oRslt = dialog.store();
this.strOpt1 = oRslt["Opt1"];
this.strOpt2 = oRslt["Opt2"];
},
"Opt1": function(dialog)
{
dialog.load({
"Opt2": this.strOpt2,
});
},
"Opt2": function(dialog)
{
dialog.load({
"Opt1": this.strOpt1
});
},
description:
{
name: "Offer of NJP",
elements:
[
{
type: "view",
elements:
[
{
type: "view",
char_height: 10,
elements:
[
{
type: "static_text",
item_id: "sta1",
height: 48,
name: "Type your initials next to the appropriate action. Then press OK and you will be \nprompted to digitally sign the AF Form 3070. Note, Fields in sections 1c and 1e will \nlock upon digitally signing in Block 2.",
char_width: 15,
alignment: "align_fill",
font: "dialog",
},
{
type: "view",
height: 28,
char_width: 8,
char_height: 8,
align_children: "align_row",
elements:
[
{
type: "edit_text",
item_id: "Opt1",
width: 50,
char_width: 8,
},
{
type: "static_text",
item_id: "txt1",
name: "I am considering punishing you under Art 15, UCMJ.",
},
]
},
{
type: "view",
height: 28,
char_width: 8,
char_height: 8,
align_children: "align_row",
elements:
[
{
type: "edit_text",
item_id: "Opt2",
width: 50,
char_width: 8,
},
{
type: "static_text",
item_id: "txt2",
name: "I am considering having the following person punish you under Art 15, UCMJ.",
},
]
},
]
},
{
type: "ok_cancel",
},
{
type: "static_text",
item_id: "stat",
name: "Designed and Coded by Lt Col Michael Hopkins",
char_width: 15,
alignment: "align_fill",
font: "dialog",
},
]
},
]
}
};
// Example Code
Offer.strOpt1 = "";
Offer.strOpt2 = "";
if("ok" == Offer.DoDialog())
{
if(Offer.strOpt1 == "" && Offer.strOpt2 == ''" {
app.alert("You must type initials in one of the fields.");
//Need code to cancel out of script, stop the execution of the digital signature, and return to dialog box for user input.
}
else
{
this.getField("01_1a1").value=Offer.strOpt1;
this.getField("01_1a2").value=Offer.strOpt2;
if (Offer.strOpt1 != "") this.getField("01_1a2_Commander").value = "";
var fieldsToLock = ["01_1a2_Commander"];
for (var i in fieldsToLock) this.getField(fieldsToLock[i]).readonly = true;
}
};

