DataType
| Kind of class: | class |
|---|---|
| Inherits from: | DataAccessor |
| Known subclasses: | |
| Classpath: | mx.data.binding.DataType |
| File last modified: | Tuesday, 18 December 2007, 15:44:38 |
The base class for all data type objects.
A data type object is a facade which gives value-added read/write access to a
data field. Functionality includes:
- validation: inspect the data to see if it's a valid value for this datatype
- conversion: convert a piece of data to/from this datatype
- formatting: parameterized conversion to/from string
- encoding: parameterized conversion to/from internal data representation
By default, a data field is simply a property of a certain component. Optionally, the data
field may be a specific sub-field within that property, identified by a location path.
A data type object is a facade which gives value-added read/write access to a
data field. Functionality includes:
- validation: inspect the data to see if it's a valid value for this datatype
- conversion: convert a piece of data to/from this datatype
- formatting: parameterized conversion to/from string
- encoding: parameterized conversion to/from internal data representation
By default, a data field is simply a property of a certain component. Optionally, the data
field may be a specific sub-field within that property, identified by a location path.
Summary
Constructor
Instance properties
- errorArray
- type : Object
- You can use the properties schema, kind, formatter, and encoder to access
- kind : mx.data.binding.DataAccessor
- formatter : mx.data.binding.Formatter
- encoder : mx.data.binding.DataAccessor
- sortInfo
- id
Instance properties inherited from DataAccessor
Class methods
Class methods inherited from DataAccessor
Instance methods
- setupDataAccessor (component:Object, property:String, location:Object)
- Initializes this object.
- getAsBoolean : Boolean
- Gets the current value, converted to a Boolean
- getAsNumber : Number
- Gets the current value, converted to a Number
- getAsString : String
- Gets the current value, converted to a String.
- setAsBoolean (newValue:Boolean)
- Sets the current value.
- setAsNumber (newValue:Number)
- Sets the current value.
- setAsString (newValue:String)
- Sets the current value.
- validationError (errorMessage:String)
- Records a validation error.
- validate (value)
- Validates the data value.
- getTypedValue (requestedType:String) : mx.data.binding.TypedValue
- getGettableTypes : Array
- Retrieves a list of types that getTypedValue can produce.
- setTypedValue (newValue:mx = .data.binding.TypedValue) : Array
- getSettableTypes : Array
- Retrieves a list of types that setTypedValue can accept.
- gettableTypes : Array
- settableTypes : Array
- validateAndNotify (returnData:Object, noEvent:Boolean, initialMessages:Array) : Array
- Validates the data in the field, and optionally dispatches the resulting valid/invalid events, as follows:
Instance methods inherited from DataAccessor
Constructor
DataType
function DataType ()Initializes a new DataType object. This would normally be called from
within Component.createField().Instance properties
encoder
errorArray
errorArray(read)The list of errors that were generated by the function "validate". Each element
of the array is an object containing these fields:- message : String
- an error message
- field : String
- [optional] name of the field or sub-field causing the error
@property errorArrayformatter
id
private id(read)kind
sortInfo
sortInfo(read)type
type:Object(read)You can use the properties schema, kind, formatter, and encoder to access
the different helper objects of this field. Some or all of them may be null.
@property schema,kind,formatter,encoderInstance methods
getAsBoolean
function getAsBoolean () : BooleanGets the current value, converted to a BooleanReturns:- the current value, expressed as a Boolean
getAsNumber
function getAsNumber () : NumberGets the current value, converted to a NumberReturns:- the current value, expressed as a Number
getAsString
function getAsString () : StringGets the current value, converted to a String.Returns:- the current value, expressed as a String
getGettableTypes
function getGettableTypes () : ArrayRetrieves a list of types that getTypedValue can produce.#Returns:- an Array of type names. When you call getTypedValue, we prefer that you request#
from it a value of one of these types.
.
Overrides:getSettableTypes
function getSettableTypes () : ArrayRetrieves a list of types that setTypedValue can accept.#Returns:- an Array of type names. When you call setTypedValue, we prefer that call it with#
a value of one of these types.
.
Overrides:gettableTypes
function gettableTypes () : ArraygetTypedValue
Returns:- the current value of the data, if we can produce it in the#
requested type. If we can't get the value as the requested type, we return null.
If the requested type is null, then we return it as whatever type we like.
Overrides:setAsBoolean
function setAsBoolean (newValue:Boolean)Sets the current value. The new value is given as a Boolean,
but will be converted to, and stored as, the appropriate internal type.Parameters:newValue:the new value, given as a BooleansetAsNumber
function setAsNumber (newValue:Number)Sets the current value. The new value is given as a Number,
but will be converted to, and stored as, the appropriate internal type.Parameters:newValue:the new value, given as a NumbersetAsString
function setAsString (newValue:String)Sets the current value. The new value is given as a String,
but will be converted to, and stored as, the appropriate internal type.Parameters:newValue:the new value, given as a StringsettableTypes
function settableTypes () : ArraysetTypedValue
function setTypedValue (newValue:mx = .data.binding.TypedValue) : ArrayParameters:newValue:A data value. Its type should be one of the type returned by getSettableTypes.#Overrides:setupDataAccessor
function setupDataAccessor (component:Object, property:String, location:Object)Initializes this object. This function should be called right after calling#
the constructor.Overrides:validate
function validate (value)Validates the data value. You should override this function in a subclass of DataType.
Call "validationError" if you find any errors. Have fun and be safe.validateAndNotify
function validateAndNotify (returnData:Object, noEvent:Boolean, initialMessages:Array) : ArrayValidates the data in the field, and optionally dispatches the resulting valid/invalid events, as follows:- If the value is null, and the field is not required,
we return null and don't dispatch any events. - If the value is null, and the field is required,
we return some errors, and dispatch an "invalid" event. - If the value is non-null and the field's type does not have a validator defined for it,
we return null and don't dispatch any events - If the value s non-null and a validator does exist, then we run the validator,
dispatch either a "valid" or "invalid" event,
and return null (for valid) or an array of messages (for invalid).
Fields that are objects with child elements will try to validate each child field
(and so on, recursively). Each individual field will dispatch a "valid" or "invalid" event if necessary.Parameters:returnData :[optional] if this field is non-null, and if we cause an event
to be dispatched, then returnData.event will be set to a copy
of that event. This is provided so you can look at the event yourself.noEvent :if true, we do not dispatch any events. If false, we DO dispatch
either a "valid" or an "invalid" event.initialMessages1:Returns:- an Array of error messages. The array contains all errors detected
either by this field, or by any sub-fields that are validatable.
This array has the same structure as the "errorArray" property
of the class mx.data.binding.DataType.
validationError
function validationError (errorMessage:String)Records a validation error. You should call this function from "validate" each time
you detect an error. It's ok to detect and report multiple errors in a single "validate"
call. If "validate" doesn't report any errors, this means the data is valid.Parameters:errorMessage:An string containing an error message - getAsBoolean : Boolean