-
3 May 2011 7:27 PM #1
[4.0.0] Models and default 'defaultValue'
[4.0.0] Models and default 'defaultValue'
Per the docs regarding the defaultValue config in Ext.data.Field:
(Optional) The default value used when a Model is being created by a Reader when the item referenced by the mapping does not exist in the data object (i.e. undefined). (defaults to "")
IMHO the defaulting to '' is a bug not a feature.
I'm finding the behavior of implicitly stuffing '' into defaultValue wrong on many levels:
(1) Principle of Least Surprise: If not explicitly specifying a defaultValue for a Field, most developers would assume it would be initialized with a NULL value, NOT an empty string.
(2) An empty string is not a sensible implicit defaultValue for any Field which is not 'string' type (i.e. date/int/etc.)
(3) When saving the Model to the backend, SQL cannot distinguish between a column which is has not been specified, vs one in which the user has actually entered an empty string in. By implicitly assuming a frontend default value of '' as opposed to NULL, a SQL default value will not be applied by the backend. Worse still, if the field was actually expected to be of 'int' type, then the empty string ('') default would cause a datatype constraint violation.
The fix to Ext.data.Field is trivial:
PHP Code:/**
* @cfg {Mixed} defaultValue
* (Optional) The default value used <b>when a Model is being created by a {@link Ext.data.reader.Reader Reader}</b>
* when the item referenced by the <code>{@link Ext.data.Field#mapping mapping}</code> does not exist in the data
* object (i.e. undefined). (defaults to [B]null[/B])
*/
defaultValue: [B]null[/B],
Thank you for reporting this bug. We will make it our priority to review this report.
Similar Threads
-
[FIXED]Model and defaultValue
By wizkid in forum Ext:BugsReplies: 3Last Post: 12 Jun 2011, 3:04 PM -
Combo defaultvalue
By n24005 in forum Ext 3.x: Help & DiscussionReplies: 3Last Post: 16 Sep 2009, 3:16 AM -
How to set the defaultValue for all new Records?
By ryanyoungsma in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 25 Jun 2009, 3:00 AM -
DefaultValue of comboBox
By issameddine in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 30 Dec 2008, 6:57 AM -
[1.1RC1] JsonReader and defaultValue
By cumpa in forum Ext 1.x: BugsReplies: 8Last Post: 14 Sep 2007, 3:57 AM


Reply With Quote