August 10, 2024
The getValidity()
method is part of the Oracle APEX JavaScript API and is used to determine the validity state of an APEX item, similar to how HTML5 form validation works. This method helps in checking whether the input for an item meets its validation constraints.
getValidity()
: This method returns an object similar to the HTML5 ValidityState
object. This object contains several properties that provide information about the validity of the item. These properties include:valid
: A Boolean value that is true
if the item is valid and false
if any constraint is violated.valueMissing
: true
if the item is required and the user has not entered a value.typeMismatch
: true
if the item’s value is not in the expected format (e.g., an invalid email address).patternMismatch
: true
if the item’s value does not match the specified pattern.tooLong
: true
if the item’s value exceeds the maximum length.rangeUnderflow
: true
if the value is below the specified minimum.rangeOverflow
: true
if the value exceeds the specified maximum.stepMismatch
: true
if the value is not a valid step (used for number inputs with a step value).customError
: true
if a custom validation error has been set.valid
: A Boolean value that is true
if the item is valid and false
if any constraint is violated.valueMissing
: true
if the item is required and the user has not entered a value.typeMismatch
: true
if the item’s value is not in the expected format (e.g., an invalid email address).patternMismatch
: true
if the item’s value does not match the specified pattern.tooLong
: true
if the item’s value exceeds the maximum length.rangeUnderflow
: true
if the value is below the specified minimum.rangeOverflow
: true
if the value exceeds the specified maximum.stepMismatch
: true
if the value is not a valid step (used for number inputs with a step value).customError
: true
if a custom validation error has been set.Here’s an example of how you might use getValidity()
to check an item’s validity and respond accordingly
1var item = apex.item("P1_EMAIL");
2var validity = item.getValidity();
3
4if (!validity.valid) {
5 if (validity.valueMissing) {
6 apex.message.alert("Please enter a value.");
7 } else if (validity.typeMismatch) {
8 apex.message.alert("Please enter a valid email address.");
9 } else if (validity.patternMismatch) {
10 apex.message.alert("The input does not match the required pattern.");
11 }
12 // Add additional checks for other validity states as needed
13}
14
getValidity()
method.The getValidity()
method provides a powerful way to handle form validation in Oracle APEX applications, enabling developers to create responsive, user-friendly interfaces with real-time feedback on data entry.
No posts found in the category "Javascript"