You are browsing documentation for version 5.0 of OroCommerce, OroCRM, and OroPlatform, maintained until August 2024 and supported until March 2026. See version 5.1 (the latest LTS version) of the Oro documentation for information on latest features.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Validation for Extended Fields

By default, all extended fields are not validated. In general, extended fields are rendered as usual forms, the same way as not extended, but there is a way to define validation constraints for all extended fields by their type.

This is done through the configuration of oro_entity_extend.validation_loader:

    class: Oro\Bundle\EntityExtendBundle\Validator\ExtendFieldValidationLoader
        - '@oro_entity_config.provider.extend'
        - '@oro_entity_config.provider.form'
            - addConstraints
                - integer
                    - Regex:
                        pattern: '^(-?[1-9]\d*|0)$'
                        message: 'This value should contain only numbers.'

        - [addConstraints, ['percent', [{ Type: {type: 'numeric'} }]]]

There are two ways to pass the constraints:

  • use a compiler pass to add the ‘addConstraints’ call with the necessary constraint configuration
  • directly call the service

Keep in mind that all constraints defined here are applied to all extended fields with a corresponding type.