Created
December 15, 2010 18:53
-
-
Save Munter/742414 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adds an 'optional' property to data type configuration, which allows undefined or null as values. | |
*/ | |
Ext.iterate(Ext.data.Types, function(key, value, obj) { | |
if (value.convert) { | |
var fn = value.convert; | |
obj[key] = { | |
convert: function (v) { | |
return (this.optional && (v === undefined || v === null)) ? null : fn(v); | |
}, | |
sortType: value.sortType, | |
type: value.type | |
}; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adds an 'optional' property to data validation configuration, which allows null as value. | |
*/ | |
Ext.iterate(Ext.data.validations, function(key, value, obj) { | |
if (Ext.isFunction(value)) { | |
var fn = value; | |
obj[key] = function (config, value) { | |
return (value === null && config.optional) || fn(config, value); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.regModel('Email', { | |
belongsTo: 'Contact', | |
fields: [ | |
{ name: 'value', type: 'string' }, | |
{ name: 'type', type: 'string', optional: true, defaultValue: null }, | |
{ name: 'primary', type: 'boolean'} | |
], | |
validations: [ | |
{ type: 'presence', field: 'value' }, | |
{ type: 'email', field: 'value' }, | |
{ type: 'inclusion', field: 'type', list: ['home', 'work', 'other'], optional: true } | |
] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment