Skip to content

Latest commit

 

History

History
executable file
·
27 lines (23 loc) · 841 Bytes

3_8.md

File metadata and controls

executable file
·
27 lines (23 loc) · 841 Bytes

3.8 Custom data transformers

If you use a custom view transformer, implement the matching transformer on the JavaScript side so validation receives the same normalized value.

For a PHP view transformer such as App\Form\DataTransformer\MyTransformer, create a JavaScript constructor with the namespace separators removed:

<script type="text/javascript">
    function AppFormDataTransformerMyTransformer() {
        /**
         * Extra options from the PHP transformer can be copied into this object.
         */
        this.extraOption = '';

        /**
         * This method is required.
         * It should return the value that will be validated.
         */
        this.reverseTransform = function(value, model) {
            // Compose the real value here.
            return value;
        };
    }
</script>