Namespace: parser

mx. parser

Formatting and parsing functionality for values.

Methods

(static) formatAttribute(obj, attr, propsnullable) → {string}

Converts an MxObject attribute to a string in the requested format.

Parameters:
Name Type Attributes Description
obj mendix/lib/MxObject

MxObject to fetch the attribute from

attr string

attribute to fetch

props Object | Object <nullable>

passed to module:mx/parser/formatValue as props parameter

Returns:

formatted value

Type
string
Example
mxobj.set("createdDate", +new Date(1980, 7, 23));
mx.parser.formatAttribute(mxobj, "createdDate",
    { datePattern: "dd-MM-yyyy" }); // 23-08-1980

(static) formatValue(value, type, propsnullable) → {string}

Converts a value to a string in the requested format.

Parameters:
Name Type Attributes Description
value *

value to convert

type string

Data type as which to interpret value. Can be one of “float”, “currency”, “autonumber”, “integer”, “long”, "decimal", “datetime”, “boolean”, “binary”, “string”, “hashstring”, “enum”.

props Object | Object <nullable>

For date conversions: parameters passed to dojo/date/locale::format. For numeric conversions: number of decimal digits to display (-1 to keep original precision), and flag indicating whether group separators should be added.

Returns:

formatted value

Type
string
Examples
mx.parser.formatValue(Big(3000), "currency"); // "3000.00"
mx.parser.formatValue(+new Date(1980, 7, 23), "datetime",
    { datePattern: "dd-MM-yyyy" }); // "23-08-1980"

(static) parseValue(value, type, propsnullable) → {number|string|Date}

Converts a string in the given format to a value.

Parameters:
Name Type Attributes Description
value string

string to convert

type string

Data type as which to interpret value. Can be one of “float”, “currency”, “autonumber”, “integer”, “long”, "decimal", “datetime”, “boolean”, “binary”, “string”, “hashstring”, “enum”.

props Object | Object <nullable>

For date conversion: parameters passed to dojo/date/locale::parse. For numeric conversion: number of decimals digits to which resulting number should be rounded to, or -1 if no rounding should be performed.

Returns:

the value if the value could be parsed, otherwise NaN for numerical types and null for the datetime type

Type
number | string | Date
Examples
mx.parser.parseValue("3,000.00", "currency"); // 3000
mx.parser.parseValue("23-8-1980", "datetime",
    { datePattern: "dd-M-yyyy" }); // Date(1980, 7, 23)