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.

Summary


Constructor
Instance properties
Instance properties inherited from DataAccessor
Class methods
Class methods inherited from DataAccessor
Instance methods

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 errorArray

formatter

(read)

id

private id
(read)

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,encoder

Instance methods

getAsBoolean

function getAsBoolean (
) : Boolean

Gets the current value, converted to a Boolean
Returns:
  • the current value, expressed as a Boolean

getAsNumber

function getAsNumber (
) : Number

Gets the current value, converted to a Number
Returns:
  • the current value, expressed as a Number

getAsString

function getAsString (
) : String

Gets the current value, converted to a String.
Returns:
  • the current value, expressed as a String

getGettableTypes

function getGettableTypes (
) : Array

Retrieves 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.
    .
    #

getSettableTypes

function getSettableTypes (
) : Array

Retrieves 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.
    .
    #

gettableTypes

function gettableTypes (
) : Array

getTypedValue

function getTypedValue (
requestedType:String) : mx.data.binding.TypedValue

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.
    #

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 Boolean

setAsNumber

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 Number

setAsString

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 String

settableTypes

function settableTypes (
) : Array

setTypedValue

function setTypedValue (
newValue:mx = .data.binding.TypedValue) : Array

Parameters:
newValue:
A data value. Its type should be one of the type returned by getSettableTypes.
#

setupDataAccessor

function setupDataAccessor (
component:Object, property:String, location:Object)

Initializes this object. This function should be called right after calling
the constructor.
#
Parameters:
component:
a component
#
property :
the name of a property of the component
#
location :
a location, in the same form as described in the EndPoint class.
#

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) : Array

Validates 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).
Validation only applies to fields which have type information available.
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