Showing posts with label Converter. Show all posts
Showing posts with label Converter. Show all posts

Thursday, 23 May 2019

JET - create and register custom converter

JET: v6.0.0
Source: GitHub

This article speaks on simplifying the process of creating and registering a custom converter in your Oracle JET application.

The entire job can be essentially broken down into 3 parts:
1. Creating the custom converter (including the logic for formatting the input data).
2. Registering the new converter with JET runtime, and finally,
3. Using the converter.

The converter which I am going to talk about is a Phone-Number-Converter. It takes in a string or a number input value, and changes the same into (###) ###-#### format. Just to keep it simple, it assumes that a phone number should always be of 10 digits.


The entire logic for the new converter is in an external file - PhoneNumberConverter.js. The converter's format method takes care of the logic for the conversion.


Next, we need a factory method (IIFE) to create an instance of this converter, as soon as it is invoked.


Finally, the converter is registered with JET runtime validation library.


Now we are all set to use this "phonenumber" converter in our code.


Cheers!