Default decimal format Oracle JETt

687 Views Asked by At

In our application we store big amount of decimal data. Conform to Oracle JET documentation there is possibility to format decimal numbers according provided pattern for individual input text controls.

But is there method to set default decimal pattern for all controls in application? Have any of you solved a similar dilemma?

1

There are 1 best solutions below

0
On

I do not believe this is possible. The default value for the converter property of <oj-input-number>, according to the documentation, is new NumberConverter.IntlNumberConverter(). There is no way to override this default value for all component instances.

However, one thing you can do in order to reduce the number of Converter instances in your code, is to create your Converter instance in a separate JavaScript module, export it and then import the binding in the viewModels you wish to reference it from.

Assuming you use a default structure and Typescript, under src/ts, create something like myConverter.ts. The content will be an exported Converter instance:

import { IntlNumberConverter } from "ojs/ojconverter-number";

export const myConverter = new IntlNumberConverter({
  maximumFractionDigits: 2,
  style: "decimal"
});

Then, in your viewModel files, you would do something like:

import { IntlNumberConverter } from "ojs/ojconverter-number";
import { ModuleViewModel } from "ojs/ojmodule-element";
import { myConverter } from "../myconverter";

class MyViewModel implements ModuleViewModel {
  public converter: IntlNumberConverter;
  constructor() {
    this.converter = myConverter;
  }
}

export = MyViewModel;

And then in your HTML, you can bind converter to your input's converter property like so:

<oj-input-number converter="[[converter]]"></oj-input-number>

This is of course not a default value for all input component instances, you still have to manually bind the converter instance in each case, but at least you only need to maintain it at one place and it only exists in memory once.