Wijmo UI for the Web
format Method
wijmo.input Namespace > IFormatValidateLib Interface : format Method

The formatting logic to use is decided based on the value type that you set here.

Valid types:

If the value type is date, the format library uses the logic of wijinputdate.

If the value is a string, the format library uses the logic of wijinputmask.

If the value type is number, the format library uses the logic of wijinputnumber.

wininputdate

With wijinputdate, the formatOrType parameter is a string value that takes a valid dateFormat object.

wijinputmask

With wijinputmask, the formatOrType parameter is a string value that takes a valid maskFormat object. The regex mask format is invalid.

wijinputnumber

With wijinputnumber, the formatOrType parameter is a string value that takes a valid type value.

wininputdate

With wininputdate, the options parameter is an object that takes five properties or null.

For more information about these options, please see InputDate.

wijinputmask

With wijinputmask, the options parameter is an object that takes two properties.

For more information about these options, please see InputMask.

wijinputnumber

With wijinputnumber, the options parameter is an object that takes eight properties.

For more information about these options, please see InputNumber.

 

Format the specified value into a string using the specified format type and options.

Syntax
var instance; // Type: wijmo.input.IFormatValidateLib;
var returnValue; // Type: string

// Parameters
var value; // Type:  any
var formatOrType; // Type:  string
var options; // Type:  any

returnValue = instance.format(value, formatOrType, options);
function format( 
   value : any,
   formatOrType : string,
   options : any
) : string;

Parameters

value

The formatting logic to use is decided based on the value type that you set here.

Valid types:

  • Javascript date, for example: new Date(2013,8,12)
  • Javascript string, for example: "1234567"
  • Javascript number, for example: 12345

If the value type is date, the format library uses the logic of wijinputdate.

If the value is a string, the format library uses the logic of wijinputmask.

If the value type is number, the format library uses the logic of wijinputnumber.

formatOrType

wininputdate

With wijinputdate, the formatOrType parameter is a string value that takes a valid dateFormat object.

wijinputmask

With wijinputmask, the formatOrType parameter is a string value that takes a valid maskFormat object. The regex mask format is invalid.

wijinputnumber

With wijinputnumber, the formatOrType parameter is a string value that takes a valid type value.

options

wininputdate

With wininputdate, the options parameter is an object that takes five properties or null.

  • amDesignator determines the string designator for hours that are "ante meridiem" (before noon).
  • culture indicates the culture that the format library uses.
  • hour12As0 is a Boolean value that determines the range of hours that can be entered in the control.
  • midnightAs0 is a Boolean value that determines whether to express midnight as 24:00.
  • pmDesignator determines the string designator for hours that are "post meridiem" (after noon).

For more information about these options, please see InputDate.

wijinputmask

With wijinputmask, the options parameter is an object that takes two properties.

  • autoConvert indicates whether to automatically convert the value to the proper format according to the format setting.
  • culture indicates the culture that the format library uses.

For more information about these options, please see InputMask.

wijinputnumber

With wijinputnumber, the options parameter is an object that takes eight properties.

  • currencySymbol determines the currency symbol when the number type is currency. The default value is according to the culture.
  • culture indicates the culture that the format library uses.
  • decimalPlaces indicates the number of decimal places to display.
  • negativePrefix determines the prefix string used for negative values. The default value is according to culture and type.
  • negativeSuffix determines the suffix string used for negative values. The default value is according to culture and type.
  • positivePrefix determines the prefix string used for positive values. The default value is according to culture and type.
  • positiveSuffix determines the suffix striing used for positive values. The default value is according to culture and type.
  • showGroup indicates whether the thousands group separator is inserted between each digital group. (The number of digits in the thousands group depends on the selected culture.)

For more information about these options, please see InputNumber.

 

Example
$.wijinputcore.format(new Date(2013,8,12));   // returns: "9/12/2013"
$.wijinputcore.format(new Date(2013,8,12), "yyyy/MM/dd");  // returns: "2013/09/12"
$.wijinputcore.format(new Date(2013,8,12),{culture: "ja-JP"});   // returns: "2013/09/12"
$.wijinputcore.format(new Date(2013,8,12,23,22,33), "tt hh:mm:ss", {culture: "ja-JP"});   // returns: "午後 11:22:33"
$.wijinputcore.format(new Date(2013,8,12,24,12,12), "HH:mm:ss", {midnightAs0: true});   // returns: "00:12:12"
   
$.wijinputcore.format("1234567", "999-9999", {autoConvert: true});   // returns: "123-4567"
$.wijinputcore.format("1234567", "999-9999", {autoConvert: false});  //  returns: "       "
    
$.wijinputcore.format(12345);   // returns: "12345.00"
$.wijinputcore.format(12345, "numeric", {decimalPlaces:3});   // returns: "12345.000"
$.wijinputcore.format(12345, "percent");   // returns: "12345.00 %"
$.wijinputcore.format(12345, "currency");  // returns: "$12345.00"
$.wijinputcore.format(12345, "currency", {culture: "ja-JP"});   // returns: "¥12345.00"
$.wijinputcore.format(12345, "numeric", {positivePrefix: "+", negativePrefix: "-"});   // returns: "+12345.00"
Remarks

Internally, Wijmo input widgets use the same format library.

For more information about formatting, please see Format Function Library

See Also

Reference

IFormatValidateLib Interface