Interface IPluginValidationRule

All Superinterfaces:
IFCPlugin, INamedUiElement, INameProviding, ITransferable, Serializable

public interface IPluginValidationRule extends IFCPlugin
Interface for validation rule plugins. A validation rule can be used to add additional data types for text input elements. For each text input element, the user can select one data type. When the user enters a value into an input element and that value does not conform to the data type, the input element is considered invalid, and an appropriate error message is shown to the user.

There are two ways how you can implement the validation logic with this plugin: either (a) via a regular expression, or (b) via custom validation logic.

Via a regular expression

This is the simpler way to implement a validation rule. You just need to implement getRegex() and return the appropriate regular expression. This regular expression is checked against the input value. When it does not match, the value is considered invalid. This will enable both client-side validation in the browser and server-side validation on the formcycle server (when server-side validation is enabled for the form field).

Via custom logic

This is the more flexible way to implement a validation rule, but also more complex. You need to implement the client-side (JavaScript) and server-side (Java) validation logic yourself.

For the server-side validation logic, override the validate(PluginValidationRuleValidateParams) method and implement it appropriately. This validation logic is applied only when server-side validation is enabled for the form field.

For the client-side validation logic, you need to add custom JavaScript that checks the value of the form field and shows an error message when the value is invalid. To add custom JavaScript, you can e.g. use an IPluginFormResources. To add custom validation logic, use the JQuery extension function $.fn.errorFunc . All input field that use this validator get a data-vdt HTML attribute set to this validator's key. Consider using the NPM package @de-xima/fc-form-renderer to access the JQuery library and other formcycle-related functions.

Author:
XIMA MEDIA GmbH
  • Method Details

    • getKey

      String getKey()
      Returns:
      A unique key that must not be shared with any other IPluginValidationRule .
    • getKeyDisplayName

      String getKeyDisplayName(Locale locale)
      Parameters:
      locale - The current locale of the designer.
      Returns:
      The name of this validation rule. This is what is shown as the name for this validation rule in the formcycle designer.
    • getRegex

      default String getRegex()
      This must return the JavaScript regular expression that check whether the value of form field is valid. Please note that the regular expression must include the initial and final slash. For example, a check for an ISBN-10 number could be written as:
      /^(?=[-0-9xX ]{13}$)(?:[0-9]+[- ]){3}[0-9]*[xX0-9]$/
      
      Furthermore, you usually want to include the start-of-string marker ^ and end-of-string marker $ to make sure the regular expression matches the entire string, not only a part of it

      The value of a form field is considered valid if this regular expression matches that value; and invalid otherwise. When the value of a form field is invalid, an appropriate error message is shown to the user.

      May return null to indicate that no regular expression-based validation should be applied. In that case, you should implement validate(params) for the server-side validation logic, and add custom JavaScript for the client-side validation logic. See the class-level documentation for more details.

      Returns:
      A JavaScript regular expression, not including the initial and final slash.
    • getValidationErrorMsg

      String getValidationErrorMsg(Locale locale)
      Parameters:
      locale - Current locale for which to show the error message.
      Returns:
      The error message that is shown to the user when they enter an invalid value in a form element.
    • isDeprecated

      default boolean isDeprecated()
      Whether this datatype is deprecated. When true, the datatype is visually shown as deprecated. Defaults to false.
      Returns:
      true if this datatype is deprecated, false otherwise.
    • validate

      Optional server-side custom validator that validates the value of a form field.

      This validation is applied in addition to the regular expression from getRegex(). Note that this validation logic is applied only when server-side validation is enabled for the form field.

      If you have custom validation, you usually want to add custom JavaScript validation logic as well. See the class-level documentation for more details on how to do this.

      Parameters:
      params - The parameters for the validation, including the value and the form field to validate.
      Returns:
      The validation result. If null is returned, the value is considered valid.
      Since:
      8.5.4