Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-2536 in a recent build.
  1. #1
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    606
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default Model.validate ~ Ext.data.Validations (presence,format) fail on undefined fields

    Model.validate ~ Ext.data.Validations (presence,format) fail on undefined fields


    REQUIRED INFORMATION
    Ext version tested:
    • sencha-touch-2.0.0-gpl
    Browser versions tested against:
    • Google Chrome 17.0.963.79 m
    DOCTYPE tested against:
    • html
    Description:
    • Validation process pass fields with a undefined value as being present or formated as some regexp might describe, though they are not. (a field with a undefined value or null value will pass the format validation with the matcher /([a-z]+)/). The format issue is more of a javascript problem, passing to reg exp "null" or "undefined" raher then null or undefined , but still this escalates in the framework.
    Steps to reproduce the problem:
    • declare a model with a few fields and a validations of type format and presence (6 fields, 3 with validation presence, 3 with validation format)
    • obtain an instance of that model
    • set a value of undefined to one required present field, a value of null to one required present field, set a value of undefined to one required formatted field, a value of null to one required formatted field, let a required present field unset, let a required formatted fireld unset
    • parse the model.validate() result
    The result that was expected:
    • at least untouched fields would be reported as invalid for the presence validation
    • fields with a undefined value would not pass the presence validation
    • at max null and undefined fields would not pass the format validation
    The result that occurs instead:
    • all fields pass the presence and format validations
    Test Case:
    Code:
        Ext.Loader.setConfig({      enabled: true
        });
        Ext.define('Model1', {
         extend: 'Ext.data.Model',
         fields: ["p1","p2","p3","f1","f2","f3"],
         validations:[
            {type:'presence',field:'p1'},
            {type:'presence',field:'p2'},
            {type:'presence',field:'p3'},
            {type:'format',field:'f1',matcher:/([a-z]+)/},
            {type:'format',field:'f2',matcher:/([a-z]+)/},
            {type:'format',field:'f3',matcher:/([a-z]+)/}
            
         ]
        });
        Ext.application({
           name: 'app',
        
        
        launch: function() {
            var  undefined, errors, 
                m = Model1.create();
            m.set('p1',undefined);
            m.set('p2',null);
            m.set('f1',undefined);
            m.set('f2',null);
            
            
            
            errors = m.validate();
            console.log(errors);
            var panel =   Ext.create('Ext.Panel', {
                fullscreen: true,
                html: 'Presence / Format test case.'
            });
            
            if(!errors || errors.length ==0)
            {
                panel.add( {html:'p1  is '+m.get('p1')+' and it is considered present.'});
                panel.add( {html:'p2  is '+m.get('p2')+' and it is considered present.'});
                panel.add( {html:'p3  is '+m.get('p3')+' and it is considered present.'});
                
                panel.add( {html:'f1  is '+m.get('f1')+' and it is considered formated /([a-z]+)/'});
                panel.add( {html:'f2  is '+m.get('f2')+' and it is considered formated /([a-z]+)/.'});
                panel.add( {html:'f3  is '+m.get('f3')+' and it is considered formated /([a-z]+)/.'});
                
            }else{
                Ext.each(errors,function(err)
                         {
                             panel.add( {html:err.field+'  '+err.message}  );
                         }
                        );
            }
         }
        });


    See this URL for live test case: http://www.senchafiddle.com/#acUO7

    Possible fix:
    • the format validation should call the presence internally and return false if the presence validation fail, maybe
    • presence validation should return false on undefined value for the field. From what I see in your code:
      Code:
       
      //http://docs.sencha.com/touch/2-0/source/Validations.html#Ext-data-Validations-method-presence
      
      presence: function(config, value) {
            if (value === undefined) {
             value = config;      
      }
            ...    
      }
    • The config passed to value doesn't make any sence to me but probably I don't see the big picture.
    Operating System:
    • win7

  2. #2
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    20
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    Thank you for the report, I know there were some issues with validations we have already fixed for the next release here: http://www.sencha.com/forum/showthre...ght=validation

    We'll check to see if this is related.

    Sencha Inc

    Jamie Avins

    @jamieavins

  3. #3
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    I am still trying to test the implications of not supporting just a single argument being passed into the presence validation method, but as far as I can tell there is no code relying on that within the framework. It was also the only validation method that did something like this.

    Could you apply the following override and see if it solves your issue?

    Code:
    Ext.apply('Ext.data.Validations', {
        presence: function(config, value) {
            //we need an additional check for zero here because zero is an acceptable form of present data
            return !!value || value === 0;
        },
        
        format: function(config, value) {
            if (value === undefined || value === null) {
                value = '';
            }
            return !!(config.matcher && config.matcher.test(value));
        }
    });

  4. #4
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    606
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    Oh, thanks, I have solved my issue as soon as I found it. I just posted here so you could fix it in the future releases

    At a first glance I would say your override would solve both issues though.

    Thanks!

  5. #5
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    Thanks for taking the time to make the report! It's little things like this that matter now that the framework itself is quite stable.

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi