Date Field and Checkboxes
I have used the two below scripts with success to cause fields to display "N/A" and become readonly when a checkbox is checked and to revert back to allowing numeric entry only that is centered when unchecking the box. I need to do the same thing except when the box is unchecked, allow only a date to be entered in the field in dd-mmm-yyyy format.
I have a checkbox with the following script:
var myText = ""; // This holds the text I want entered in all the boxes
var myField; // Field object variable
var myFieldReadonly = false; // boolean for readonly property
/* if the box is checked, then enter N/A into all the fields
and also set to readonly. Otherwise, empty any text and
allow text entry into all fields.
*/
if (event.target.isBoxChecked(0)){
myText = "N/A";
myFieldReadonly = true;
} else {
myText = '';
myFieldReadonly = false;
}
// Loop through items 1 through 2 and set properties
for (x = 1; x <= 2; x++) {
myField = this.getField("Group5.Text" + x);
myField.value = '';
myField.readonly = myFieldReadonly;
myField.value = myText;
if (myFieldReadonly == true) {
myField.alignment = "center";
} else {
switch (x) {
case 1: myField.alignment = "center"; break;
case 2: myField.alignment = "center"; break;
}
}
}
I have the below script on a field (under the format tab -> custom -> Custom Keystroke Script) where when the checkbox is unchecked, it makes the field only allow numbers and not letters:
if (this.getField("Check Box4").value != null) {
if(!event.willCommit){
event.rc = !isNaN(event.change) || event.change == ".";
//event.rc = /^[\d.,]+$/.test(event.change);
}
}
The two fields that this appiles to are text fields with date formating. When I uncheck the box, I want the fields to go back to only allowing a date to be entered in the field.
