Myna. ValidationResult

Stores the results of one or more validation operations

Detail

A validation result starts out representing a successful operation.  Calls to addError will change success to false, and store the error.  Multiple ValidationResult objects can be merged via the merge function, allowing several operations to return a single result object.  ValidationResult is primarily used to return information to the browser regarding the status of an AJAX call, and ValidationResult.toJson() will return an appropriate JSON string for an Ext form submit action.  ValidationResult objects are also returned by <Myna.DataManager.beanTemplate> “set” functions

Example

Myna.DataManager.beanTemplate.setFields=function(fields){
var bean = this;
var result = new Myna.ValidationResult();
fields.getKeys().forEach(function(name){
if (bean.columnNames.indexOf(name) != -1){
result.merge(bean["set_"+name](fields[name]));
}
})

return result;
}

bean.baseBean["set_"+fname] = function (newval){
var result = new Myna.ValidationResult();
if (typeof newval === "undefined"){
result.addError("argument 'newval' required for set" +fname +".",fname);
return result;
}
if (newval != this.data[arguments.callee.fieldName]){
result.merge(this.saveField(arguments.callee.fieldName,newval));
this.data[arguments.callee.fieldName] = newval;
}
return result;
}
Summary
Myna. ValidationResultStores the results of one or more validation operations
Properties
successBoolean result status for this ValidationResult default true
errorsobject containing errors keyed by property name default {}
errorMessageOverall error message for this ValidationResult
errorDetailAll messages added via addError without a property parameter
Functions
Myna. ValidationResultContructs a ValidationResult Object
addErrorAdds an error to this result and sets success to false
mergeMerge a ValidationResult into this one, optionally changing the errors properties

Properties

success

Boolean result status for this ValidationResult default true

This is set to false automatically when addError is called, or a ValidationResult object with success=false is merged

errors

object containing errors keyed by property name default {}

Errors are added to this object automatically when addError is called with a property parameter

errorMessage

Overall error message for this ValidationResult

This field is not set automatically

errorDetail

All messages added via addError without a property parameter

Functions

Myna. ValidationResult

Myna.ValidationResult = function(validation)

Contructs a ValidationResult Object

Parameters

validationOptional default undefined a ValidationResult object to act as the base for this object

addError

Myna.ValidationResult.prototype.addError=function(message,
property)

Adds an error to this result and sets success to false

Parameters

messageHTML message to add
propertyOptional default undefined If defined, will save message to errors by this property Returns: reference to this ValidatinResult

merge

Myna.ValidationResult.prototype.merge=function(validation,
prefix)

Merge a ValidationResult into this one, optionally changing the errors properties

Parameters

validationa ValidationResult object to merge wit this one
prefixOptional default undefined If defined, this string will be prepended to the validation.errors before merging

Detail

Myna.ValidationResult.prototype.addError=function(message,
property)
Adds an error to this result and sets success to false
Myna.ValidationResult = function(validation)
Contructs a ValidationResult Object
Boolean result status for this ValidationResult default true
Myna.ValidationResult.prototype.merge=function(validation,
prefix)
Merge a ValidationResult into this one, optionally changing the errors properties
object containing errors keyed by property name default {}