Namespace

parser

mx.parser

Formatting and parsing functionality for values.

Methods

# static formatAttribute(obj, attr, propsopt) → {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 <optional>

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

formatted value

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, propsopt) → {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 “autonumber”, “integer”, “long”, "decimal", “datetime”, “boolean”, “binary”, “string”, “hashstring”, “enum”.

props Object <optional>
selector "date" | "time" | "datetime" <optional>

For date conversions: only format the date, time or both.

datePattern string <optional>

For date conversions: custom pattern to use for formatting.

places number <optional>

For numeric conversions: number of decimal digits to display (-1 to keep original precision).

groups boolean <optional>

For numeric conversions: flag indicating whether group separators should be added.

formatted value

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

# static parseValue(value, type, propsopt) → {external:Big|string|Date|boolean}

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 “autonumber”, “integer”, “long”, "decimal", “datetime”, “boolean”, “binary”, “string”, “hashstring”, “enum”.

props Object <optional>
selector "date" | "time" | "datetime" <optional>

For date conversions: only format the date, time or both.

datePattern string <optional>

For date conversions: custom pattern to use for formatting.

places number <optional>

For numeric conversions: number of decimal digits to display (-1 to keep original precision).

groups boolean <optional>

For numeric conversions: flag indicating whether group separators should be added.

the value if the value could be parsed, otherwise null. The return type depends on the type of the attribute as follows:

Attribute type Return type
Integer, Long, Decimal external:Big
Autonumber string
DateTime Date
Enum string
String string
Boolean boolean
external:Big | string | Date | boolean
Examples
mx.parser.parseValue("3,000.00", "decimal"); // Big(3000)
mx.parser.parseValue("23-8-1980", "datetime",
    { datePattern: "dd-M-yyyy" }); // Date(1980, 7, 23)