FormFieldValueFormat Class
Specifies formatting and validation settings for a PDF form field value.
Declaration
public class FormFieldValueFormat extends JavaObject
Remarks
The following code snippet configures a text field to accept dates in the MMMM/dd/yyyy format:
// Create a text field.
TextBoxField dateField = new TextBoxField("Date");
// Apply a date format.
dateField.setValueFormat(FormFieldValueFormat.createDateTimeFormat("MMMM/dd/yyyy"));
pdfDocument.getFields().add(dateField);
Refer to the following help topic for additional information: Format and Validate PDF Form Field Values.
Inherited Members
Inheritance
FormFieldValueFormat()
Initializes a new instance of the FormFieldValueFormat class.
Declaration
public FormFieldValueFormat()
Methods
createDateTimeFormat(String format) Method
Creates a value format configuration for date and time values.
Declaration
public static FormFieldValueFormat createDateTimeFormat(String format)
Parameters
| Name | Type | Description |
|---|---|---|
| format | String | The date and time format string. |
Returns
| Type | Description |
|---|---|
FormFieldValueFormat |
A value format configuration for date and time values. |
createNumberFormat(int decimalPlaces, FormFieldNumberSeparatorStyle separatorStyle, String currencySymbol, FormFieldCurrencyStyle currencyStyle, FormFieldNegativeNumberStyle negativeNumberStyle) Method
Creates a value format configuration for numeric values with currency and negative number settings.
Declaration
public static FormFieldValueFormat createNumberFormat(int decimalPlaces, FormFieldNumberSeparatorStyle separatorStyle, String currencySymbol, FormFieldCurrencyStyle currencyStyle, FormFieldNegativeNumberStyle negativeNumberStyle)
Parameters
| Name | Type | Description |
|---|---|---|
| decimalPlaces | int | The number of digits after the decimal separator. |
| separatorStyle | FormFieldNumberSeparatorStyle | The number separator style. |
| currencySymbol | String | The currency symbol. |
| currencyStyle | FormFieldCurrencyStyle | The placement style of the currency symbol. |
| negativeNumberStyle | FormFieldNegativeNumberStyle | The display style for negative numbers. |
Returns
| Type | Description |
|---|---|
FormFieldValueFormat |
A value format configuration for numeric values. |
createNumberFormat(int decimalPlaces, FormFieldNumberSeparatorStyle separatorStyle) Method
Creates a value format configuration for numeric values.
Declaration
public static FormFieldValueFormat createNumberFormat(int decimalPlaces, FormFieldNumberSeparatorStyle separatorStyle)
Parameters
| Name | Type | Description |
|---|---|---|
| decimalPlaces | int | The number of digits after the decimal separator. |
| separatorStyle | FormFieldNumberSeparatorStyle | The number separator style. |
Returns
| Type | Description |
|---|---|
FormFieldValueFormat |
A value format configuration for numeric values. |
createPercentFormat(int decimalPlaces, FormFieldNumberSeparatorStyle separatorStyle) Method
Creates a value format configuration for percentage values.
Declaration
public static FormFieldValueFormat createPercentFormat(int decimalPlaces, FormFieldNumberSeparatorStyle separatorStyle)
Parameters
| Name | Type | Description |
|---|---|---|
| decimalPlaces | int | The number of digits after the decimal separator. |
| separatorStyle | FormFieldNumberSeparatorStyle | The number separator style. |
Returns
| Type | Description |
|---|---|
FormFieldValueFormat |
A value format configuration for percentage values. |
createSpecialFormat(FormFieldSpecialFormatType format) Method
Creates a value format configuration that uses the specified predefined special format.
Declaration
public static FormFieldValueFormat createSpecialFormat(FormFieldSpecialFormatType format)
Parameters
| Name | Type | Description |
|---|---|---|
| format | FormFieldSpecialFormatType | The predefined special format type. |
Returns
| Type | Description |
|---|---|
FormFieldValueFormat |
A value format configuration that uses the specified predefined special format. |
createSpecialFormat(String formatMask) Method
Creates a value format configuration that uses the specified special format mask.
Declaration
public static FormFieldValueFormat createSpecialFormat(String formatMask)
Parameters
| Name | Type | Description |
|---|---|---|
| formatMask | String | The special format mask. |
Returns
| Type | Description |
|---|---|
FormFieldValueFormat |
A value format configuration that uses the specified special format mask. |
createTimeFormat(String format) Method
Creates a value format configuration for time values.
Declaration
public static FormFieldValueFormat createTimeFormat(String format)
Parameters
| Name | Type | Description |
|---|---|---|
| format | String | The time format string. |
Returns
| Type | Description |
|---|---|
FormFieldValueFormat |
A value format configuration for time values. |
getCalculateScript() Method
Returns a JavaScript code used to recalculate the field value.
Declaration
public String getCalculateScript()
Returns
| Type | Description |
|---|---|
| String | The JavaScript code used to recalculate the field value. |
getFormatScript() Method
Returns a JavaScript code used to format the field value.
Declaration
public String getFormatScript()
Returns
| Type | Description |
|---|---|
| String | The JavaScript code used to format the field value. |
getKeystrokeScript() Method
Returns a JavaScript code used to process keystrokes.
Declaration
public String getKeystrokeScript()
Returns
| Type | Description |
|---|---|
| String | The JavaScript code used to process keystrokes. |
getValidateScript() Method
Returns a JavaScript code used to validate the field value.
Declaration
public String getValidateScript()
Returns
| Type | Description |
|---|---|
| String | The JavaScript code used to validate the field value. |
setCalculateScript(String value) Method
Sets a JavaScript code used to recalculate the field value.
Declaration
public void setCalculateScript(String value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | String | The JavaScript code used to recalculate the field value. |
setFormatScript(String value) Method
Sets a JavaScript code used to format the field value.
Declaration
public void setFormatScript(String value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | String | The JavaScript code used to format the field value. |
Remarks
The following code snippet formats the entered value and inserts hyphens between characters:
TextBoxField textField = new TextBoxField("Code");
FormFieldValueFormat format = new FormFieldValueFormat();
format.setFormatScript(
"if (event.value != '') {" +
"var value = event.value;" +
"event.value = '';" +
"for (var i = 0; i < value.length - 1; i++)" +
" event.value += value.charAt(i) + '-';" +
"event.value += value.charAt(value.length - 1);" +
"}");
textField.setValueFormat(format);
pdfDocument.getFields().add(textField);
// Bind the field to a widget and place it on the page.
RectangleF bounds = new RectangleF(120, 720, 220, 20);
TextBoxWidgetAnnotation widget = new TextBoxWidgetAnnotation(textField, bounds);
page.getAnnotations().add(widget);
Refer to the following help topic for additional information: Use JavaScript to Format Input.
setKeystrokeScript(String value) Method
Sets a JavaScript code used to process keystrokes.
Declaration
public void setKeystrokeScript(String value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | String | The JavaScript code used to process keystrokes. |
Remarks
The following code snippet allows users to enter only numeric characters:
FormFieldValueFormat format = new FormFieldValueFormat();
format.setKeystrokeScript(
"var re = /^[0-9]+$/;" +
"if (event.value != '') {" +
" event.rc = re.test(event.value);" +
"}");
textField.setValueFormat(format);
setValidateScript(String value) Method
Sets a JavaScript code used to validate the field value.
Declaration
public void setValidateScript(String value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | String | The JavaScript code used to validate the field value. |
Remarks
The following code snippet uses a JavaScript validation action to ensure that users enter a valid email address:
FormFieldValueFormat format = new FormFieldValueFormat();
format.setValidateScript(
"if (event.value.indexOf('@') == -1) {" +
" app.alert('Invalid email');" +
" event.rc = false;" +
"}");