Oracle APEX is an incredibly powerful platform for building web applications, and one of its standout features is the ability to create custom plugins. This post explores an introductory example of implementing custom validation logic for text fields using an Oracle APEX plugin, combining both server-side and client-side logic to deliver flexibility and a seamless user experience. For more details, you can visit the plugin on APEX World through this link, where you can explore and consult it further.

This article is designed as a starting point, and in future posts, we will expand on this foundation to tackle more complex validation scenarios.

What Does This Plugin Do?

The main goal of this plugin is to ensure that any text entered into a field starts with a predefined prefix. This prefix is configured as a custom attribute within the plugin’s settings, making it reusable and adaptable to different requirements.

While this validation is simple, it provides a solid base for building more advanced functionalities. The plugin integrates seamlessly with Oracle APEX, using methods like render_plugin to generate dynamic HTML and extend standard JavaScript functions for real-time validation.

Key Features of the Plugin

  1. Real-Time Custom Validation

    The plugin overrides two key JavaScript methods in the Oracle APEX API to enable client-side validation:

    • getValidity: Checks whether the field is empty or if the text does not start with the expected prefix.

    • getValidationMessage: Generates clear, specific error messages based on the validation results.

  2. Dynamic Rendering Procedure

    The PL/SQL render_plugin procedure handles the dynamic generation of the input field’s HTML and synchronizes the entered value with the Oracle APEX session state. It also includes JavaScript code to initialize the validation logic in the user’s browser.

  3. Predefined and Customizable Messages

    Developers can configure translatable error messages to ensure consistency in global applications. Examples include:

    • “This field cannot be empty”

    • “The value must start with the prefix ‘%0′”

  4. Expandable Design

    The plugin is designed to be reusable and adaptable. Although this example is basic, it can be extended to include more complex validations and dynamic rules in future implementations.

How the Plugin Works

To ensure a seamless user experience, this Oracle APEX plugin combines client-side and server-side validation to enforce a specific text format. By leveraging the apex.item API for real-time input validation and the PL/SQL render_plugin procedure for dynamic rendering, the plugin effectively validates user input before submission.

Below, we break down the two key components of this functionality:

JavaScript Validation Logic

The plugin extends Oracle APEX’s apex.item API to validate user input in real time. Here’s how it works:

  • Detects Empty Fields: If the field is empty, it is flagged as invalid.

  • Validates Prefix: If the entered text does not start with the required prefix, an error message is displayed.

  • Displays Clear Error Messages: Messages are dynamically generated and displayed consistently with Oracle APEX’s standard validation flow.

Dynamic Rendering with PL/SQL

The render_plugin procedure builds the HTML structure for the input field and attaches the JavaScript logic to ensure smooth integration. Key actions include:

  • Setting the field’s value in the Oracle APEX session state.

  • Outputting a dynamically generated input field with labels and error placeholders.

  • Injecting JavaScript code to initialize the validation logic on the client side.

What’s Next?

This plugin serves as an initial approach to custom validation in Oracle APEX. While the current implementation is straightforward, it sets the stage for more advanced validation scenarios. Future articles will cover:

  • Conditional validations based on user input.

  • Validations involving multiple fields.

  • Advanced error handling with dynamic messaging.

  • Integrating server-side logic for complex rules.

For further details and additional resources, visit our website at Novoshore or find the source code on GitHub. To learn how to work with this plugin in your own Oracle APEX projects, check out our detailed post on building this plugin step by step. Stay tuned as we continue to expand this series with increasingly advanced techniques for Oracle APEX plugins!