Applies To: Information Worker for SharePoint 2013/2016 and Cloud
Validation runs when the associated field value changes. The purpose of field level validation is to verify that the input to a field is entered correctly.
Object
event | All JavaScript scripts are executed as the result of a particular event. For each of these events, JavaScript creates an event object. During the occurrence of each event, you can access this object to get and possibly manipulate information about the current state of the event. Each event has a type and a name property that uniquely identify the event. This section describes all the events, listed as type/name pairs, and indicates which additional properties, if any, they define. |
Properties
value |
Is the value that the field contains when it is committed. For example, the following JavaScript verifies that the field value is between zero and 100: if (event.value < 0 || event.value > 100) { |
target |
The target object that triggered the event. In all mouse, focus, blur, calculate, validate, and format events, it is the Field object that triggered the event. In other events, such as age open and close, it is the Doc or this object. |
Field properties and methods affect field-level attributes
calcOrderIndex, charLimit, comb, currentValueIndices, defaultValue, doNotScroll, doNotSpellCheck, delay, doc, editable, exportValues, fileSelect, multiline, multipleSelection, name, numItems,page, password, readonly, required, submitName, type, userName, value, valueAsString, clearItems, browseForFileToSubmit, deleteItemAt, getItemAt, insertItemAt, setAction, setItems,signatureInfo, signatureSign, signatureValidate.
Field properties and methods affect widget-level attributes
alignment, borderStyle, buttonAlignX, buttonAlignY, buttonPosition,buttonScaleHow, buttonScaleWhen, display, fillColor, hidden, highlight,lineWidth, print, rect, strokeColor, style, textColor, textFont, textSize, buttonGetCaption, buttonGetIcon, buttonImportIcon, buttonSetCaption, buttonSetIcon, checkThisBox, defaultIsChecked, isBoxChecked, isDefaultChecked, setAction, setFocus
Get reference to data field or control:
this.getField('TextField1')
Scripts, which are executed on specific control (e.g. Button click) have “event.target” variable set to current control.
event.value
- gets value of current control.
Manipulate fields /controls
Get field value:
Getting the value of the field data that the user has entered. Depending on the type of the field, may be a String, Date, or Number.
var fieldValue = this.getField("TextField1").value;
Getting string value from field
var fieldStringValue = this.getField("TextField1").valueAsString;
Change field value:
event.value = 'Changed value';
Show alert message:
app.alert({cMsg: "Error! Try again!", cTitle: "Title here" });
cMsg | A string containing the message to be displayed. |
nIcon (optional) | An icon type. Possible values are these: 0 — Error (default) 1 — Warning 2 — Question 3 — Status |
nType (optional) | A button group type. Possible values are these: 0 — OK (default) 1 — OK, Cancel 2 — Yes, No 3 — Yes, No, Cancel |
cTitle (optional, Acrobat 6.0) | The dialog box title. If not specified, the title “Adobe Acrobat” is used. |
Make control visible / hidden:
event.target.hidden = false; event.target.hidden = true;
Get data from data source:
dataList = DataSources['ListName']; this.getField('TextField1').value = dataList[0]['columnName'];
Example
Following code checks on field exit if field equals "Hello World". If it does not, then entered text becomes red
if (event.value != "" && event.value != "Hello World")
{
app.alert("The entered value needs to be Hello World");
event.target.textColor = color.red;;
}
else
{
event.target.textColor = color.black;
}
Scripting reference and more examples can be found in JavaScript for Acrobat API Reference.
0 Comments