Mendix Client 5 API Documentation


mendix.lib.ObjectValidation

mendix.lib.ObjectValidation contains the messages of a failed MxObject validation. The terms fields and attributes are used interchangeably, so some methods have aliases reflecting this.

Methods

getGUID()

Returns GUID of the validated MxObject.

Returns

Type Description
String The GUID of the validated object.

Example

val.getGUID();  // "12345"

getFields(), getAttributes()

Returns attributes which did not pass validation.

Returns

An array of Objects with the following contents:

Key Type Description
name String The attribute that did not pass validation.
reason String A description of the reason why the validation did not pass.

Example

val.getFields();    // [ { name: "Username", reason: "Username already in use" },
                    //   { name: "ZipCode", reason: "Zip code is invalid" } ] 

addField(attr, message), addAttribute(attr, message)

Add validation message message for attribute attr if there isn’t one. Returns true if there is no message for attr, false otherwise.

Parameters

Key Type Description
attr String The attribute of the validation field.
message String The message describing the failed validation.

Examples

val.addField("Username", "Username already in use");

removeField(attr), removeAttribute(attr)

Remove the validation message of attribute attr. Returns false if there is no message for attr, true otherwise.

Parameters

Key Type Description
attr String The attribute of the validation field to be removed.

Examples

val.removeField("Username");

getErrorReason(attr)

Returns the validation message of attr.

Parameters

Key Type Description
attr String The attribute to return the validation message for.

Examples

val.getErrorReason("Username"); // "Username already in use"

clone()

Returns a clone of this ObjectValidation object.

Examples

var clonedVal = val.clone();
clonedVal.getErrorReason("Username") === val.getErrorReason("Username");    // true