Interface IPluginValidationRule
- All Superinterfaces:
IFCPlugin, INamedUiElement, INameProviding, ITransferable, Serializable
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
-
Field Summary
Fields inherited from interface IFCPlugin
CONFIG_FILENAMEFields inherited from interface INamedUiElement
ATTR_DISPLAY_NAMEFields inherited from interface INameProviding
ATTR_NAME, COL_NAME -
Method Summary
Modifier and TypeMethodDescriptiongetKey()getKeyDisplayName(Locale locale) default StringgetRegex()This must return the JavaScript regular expression that check whether the value of form field is valid.getValidationErrorMsg(Locale locale) default booleanWhether this datatype is deprecated.Optional server-side custom validator that validates the value of a form field.Methods inherited from interface IFCPlugin
getDescription, getDescription, getDisplayName, getName, initialize, initPlugin, install, shutdown, shutdown, uninstall, validateConfigurationData
-
Method Details
-
getKey
String getKey()- Returns:
- A unique key that must not be shared with any other
IPluginValidationRule.
-
getKeyDisplayName
-
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 itThe 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
-
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
-