This is the second of four exercises that were part of the LiveCycle best practices lab at MAX
Implement Field Validation
Open EX2 Validation.pdf in Designer
- Preview and click the “Submit by email” button to validate the form
- Errors are reported with message boxes.
- Selecting the error message in the listbox highlights the error field
- Tabbing out of the listbox will set focus to the selected error field.
- Change the form properties to customize error handling to: “Don’t show any message boxes”
- Modify the (propagated) validationState event under the root subform:
- On error: color fields and modify the toolTip value
- Else: revert field color and toolTip
- Add a change event to the phone number to restrict entry to digits
The solution file is: EX2 Validation (Solution).pdf
Reverting changes to fields:
To write re-usable code for changing values back to their original state, we should never hard-code the changes. E.g. we should never revert a color by writing: Field.fillColor = "255,255,255". The original color may not have been white.
Rather, after modifying an element, we can revert by removing the changed element. Removing an element forces the XFA processor to use the original value found in the form template.
E.g. Change the font color by modifying the font.fill.color element:
Field.font.fill.color.value = "255,0,0";
Revert the change by removing the color element:
Or by removing one of the ancestor properties:
- In the change event, xfa.event.change holds the contents of your key stroke (or paste buffer)
- E.g. force all input to upper case:
xfa.event.change = xfa.event.change.toUpperCase();