PDA

View Full Version : Ext 4.0.5 store.sync Presence zero value validation bug



ValterBorges
27 Jul 2011, 1:58 PM
Situation:

A record that has a model with a int type and gets set to zero will make the record.dirty = true.
store.getUpdatedRecords() returns the updated record and everything is well.

The presence function returns false because !!0 = false although there is a value present

presence: function(config, value) {
if (value === undefined) {
value = config;
}

return !!value; //this should check if value !== 0 because zero is a valid and can be present
},

Now sure how this affects store from synching but it it's. It must be coded not to sync if validation fails.

abe.elias
27 Jul 2011, 5:27 PM
I know Ed fixed this. Let me find out why it didn't make it in.

edspencer
27 Jul 2011, 5:47 PM
This was applied to the 4.1.0 branch. I've just cherry picked it back to 4.0.6 so it will be present in that release. In the mean time you can override it with this patch:



Ext.apply(Ext.data.validations, {
presence: function(config, value) {
if (value === undefined) {
value = config;
}

//we need an additional check for zero here because zero is an acceptable form of present data
return !!value || value === 0;
},

/**
* Returns true if the given value is between the configured min and max values.
* For example:
*
* validations: [{type: 'length', field: 'name', min: 2}]
*
* @param {Object} config Config object
* @param {String} value The value to validate
* @return {Boolean} True if the value passes validation
*/
length: function(config, value) {
if (value === undefined || value === null) {
return false;
}

var length = value.length,
min = config.min,
max = config.max;

if ((min && length < min) || (max && length > max)) {
return false;
} else {
return true;
}
}
});

ValterBorges
28 Jul 2011, 6:05 AM
When do you expect 4.0.6 to be out? 4.1.0?

edspencer
28 Jul 2011, 9:55 AM
Typically patch releases are every 2-3 weeks though we might push this one out sooner

Simon178
27 Mar 2012, 4:12 AM
Hi there,

it seems there is quite the same problem with boolean values and validation for presence.

Suggestion:
return !!value || value === 0 || value === false;

or am i wrong?

regard,
Simon