Description
A custom data type is a class that checks the validity of the input value and converts the value provided by the HTML control into a specific type. For example a textbox value is a string, but if the data type is declared as an integer, the returned value will be converted into a JavaScript int.
The declaration of a new data type is done with a call to jQuery.iField.registerDataType(dataTypeName, settings).
Example
The following example is the standard 'int' data type. It converts a string into an integer and back. The onValidate() method checks with a regular expression that the string value is a number.
jQuery.iField.registerDataType('int',{
onValidate:function(){
return (/^\d+$/).test(this.get());
},
getTyped:function(){
if(this.onValidate())
return parseInt(this.get());
else
return undefined;
},
setTyped:function(value){
return this.set(value===undefined?'':value.toString());
}
});