View Full Version : Presence Validation type returns true on null values.

6 Jul 2011, 11:43 AM
The presence model validator has the unexpected behavior of returning true if the value passed in is nul
the only check in presence is ( value == undefined ).

null will always return true.

It seems like a javascript gotcha. an empty string will evaluate to false, but null will evaluate to true. Technically and empty string is more of a value than a null value. And in the case of a data model, a null value would imply no value and should fail presence validation.

null, empty string and undefined should return false.

6 Jul 2011, 12:09 PM
Sencha Touch version tested:


Platform tested against:



The presence validator will return true if fed a null value and false for an empty string

Test Case:

Ext.data.validation.presence( {}, null );

Steps to reproduce the problem:

Create a model with a presence validator
Create an instance of said model
enter a null value
run validation routine

The result that was expected:


The result that occurs instead:


Debugging already done:

I change the function to return the boolean equivelant of the value passed im

Possible fix:

Ext.data.validations.presence = function( config, value){
var zeroVal = parseInt( value, 10 ) || value;

return zeroVal === 0 ? true: !!value ;

6 Jul 2011, 12:10 PM
This is actually a pretty easy fix

Ext.data.validations.presence = function( config, value){
var zeroVal = parseInt( value ) || value;

return value == 0 ? true: !!value ;

Not really sure what the value = config line was accomplishing in the original function, but !!value seems to give the expected behavior.