You found a bug! We've classified it as a bug in our system. We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Ext User Joe's Avatar
    Join Date
    Apr 2007
    Posts
    243
    Vote Rating
    0
    Joe is on a distinguished road

      0  

    Default [CLOSED-33] [3.0rc2]TextField - validation fails - even when turned off

    [CLOSED-33] [3.0rc2]TextField - validation fails - even when turned off


    Bug #1
    When validationEvent is set to false and validateOnBlur is set to false on a Field (i.e. TextField or Combobox) then there should be no validation.

    I found two cases where the Field validates when validation is turned off ...
    1) When you use setValue on a TextField
    2) When you select value in a combobox

    In both cases, the root cause of the problem is the setValue method in Ext.form.Field running the validate method regardless of validationEvent value.

    Note: There was an old bug logged for 1.1 (the only reference to this I found in search).
    http://extjs.com/forum/archive/index.php/t-5330.html

    I did not use the exact same logic as used in the above post for the reasons mentioned below.

    How to recreate the problem.

    Use the following code and ..
    1) Press the Update button to see the TextField validate incorrectly.
    2) Update the Combobox to see the Combo validate incorrectly.

    Code:
    //========= Demo Simple Form Showing Error ============
    var formPanel;
    
    function validateMe(){
    	if (formPanel.getForm().isValid()){
    		alert( 'We passed!' );
    		return;
    	};
    	formPanel.getForm.applyToFields({validationEvent:'Blur'});
    };
    
    function updateMe(){
    	var myField = Ext.getCmp('fldTitle').setValue("");
    };
    
    
    Ext.onReady(function(){
         Ext.QuickTips.init();
    
    	var fields = [
    		{xtype:'textfield', id:'fldTitle', fieldLabel: 'Title', name:'Title',
    			validator:function(){return'failed validation'},
    			validateOnBlur:false,
    			validationEvent:false
    		},
    		{xtype:'combo', fieldLabel: 'Selection', name:'Selection',store:['One','Two','Three'], 
    			validator:function(){return'failed validation'},
    			validateOnBlur:false,
    			validationEvent:false
    		}
    	];
    	
    	formPanel = new Ext.FormPanel({
    		tbar: [
    			{text: 'Validate', onClick: validateMe},
    			{text: 'Update', onClick: updateMe}
    		],
    		title: 'New Form', 
    		width: 450,
    		height: 350,
    		renderTo: Ext.getBody(),
    		items: fields
    	});
    
    });

    I propose updating to something close to the following code .. which fixed both errors.
    Code:
    Ext.override( Ext.form.Field, {
        setValue : function(v){
            this.value = v;
            if(this.rendered){
                this.el.dom.value = (Ext.isEmpty(v) ? '' : v);
                 //--- *Joe - was just calling validate with no checking, causing validation to kick off - even when turned off
                //this.validate();
                //--- This line only validates if the validationEvent is not turned off or if on blur .. the current field is not the one being set (i.e. in the case of combo)
               if(this.validationEvent !== false || ((this.validateOnBlur || this.validationEvent === "blur") & this.hasFocus !== true ) ){
    	            this.validate() 
               }
            };
            return this;
        }
    })

    It is odd to have a validateOnBlur and a validationEvent with an option for 'Blur'. In version 3.0 maybe it is time to get rid of redundancy and have validateOnBlur simply set the validationEvent to 'Blur' or remove it all together.

    But .. if you must keep it, then at least make it work the same for TextBox and ComboBox.

    Bug #2
    When you have validationEvent set to false and leave the defaults for TextBox and Combo (both true). What you will find is that even though the TextBox has validateOnBlur set to true .. it does not validate on blur .. but the Combobox does. That code should be the same as the fixed code or to whatever you add to the above update routine so they work the same.

    The below code makes textbox and combo work the same when validationEvent = false and validateOnBlur (arg) is set to true.

    Code:
    Ext.override( Ext.form.Field, {
        // private
        onBlur : function(){
            this.beforeBlur();
            if(this.focusClass){
                this.el.removeClass(this.focusClass);
            }
            this.hasFocus = false;
            //if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
            if(this.validationEvent !== false || (this.validateOnBlur || this.validationEvent === "blur") ){            this.validate();
            }
            var v = this.getValue();
            if(String(v) !== String(this.startValue)){
                this.fireEvent('change', this, v, this.startValue);
            }
            this.fireEvent("blur", this);
        }
    })
    Thanks
    Joseph Francis,
    CoreLan / Meeting Consultants

  2. #2
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    5
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    The docs already state though that validation will be performed when using setValue. The docs state if you want to bypass validation you should use setRawValue.

  3. #3
    Ext User Joe's Avatar
    Join Date
    Apr 2007
    Posts
    243
    Vote Rating
    0
    Joe is on a distinguished road

      0  

    Default Sorry .. but wrong ...

    Sorry .. but wrong ...


    STOP - THIS IS A BUG.

    When a field has validateOnBlur:false and validationEvent:false then why should validation occur?
    Joseph Francis,
    CoreLan / Meeting Consultants

  4. #4
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    5
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    I see you have a validator specified also. Have you tested with the code in svn? The validation was tweaked slightly. Upon specifying a validator it trumps everything else so you can customize the behavior to your desire.

  5. #5
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    5
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    FYI I did not alter the status of the thread; I was making comments.

    I was wondering if the validate() method would be the better place to check for validationEvent. If it is false, don't call validateValue(). Not sure about that clearInvalid though, I suppose that should be bypassed also.

    Code:
        validate : function(){
            if(this.disabled || this.validationEvent === false || this.validateValue(this.processValue(this.getRawValue()))){
                this.clearInvalid();
                return true;
            }
            return false;
        },

  6. #6
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    83
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    No, that won't work. The whole point of disabling validation events is to defer validation until required. In that case manual validation should still be possible.

  7. #7

  8. #8
    Ext User Joe's Avatar
    Join Date
    Apr 2007
    Posts
    243
    Vote Rating
    0
    Joe is on a distinguished road

      0  

    Default So are we back to setValue fix?

    So are we back to setValue fix?


    Good point - while that code did fix the bug, I see the point by Condor that makes it not a viable option.

    Is there any issue updating the TextField code where it calls validate with no checks (my original post)?

    I just can't see any times where you would want the validationEvent set to false (meaning I want to manually validate) and then have setValue always validate and show a red box.

    Thanks
    Joseph Francis,
    CoreLan / Meeting Consultants

  9. #9
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,105
    Vote Rating
    114
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    validationEvent should provide a means to turn on and off UI triggered events. It should not be used as a means to dsiable validation completely.

    We will be implementing the following changes:
    1. Deprecate validateOnBlur but continue to support it by appending to validationEvent array.
    2. validationEvent can be either a string event name or an array of events. The default will be ['blur','keyup']
    3. Document that validationEvent is for automatically occurring events in the UI.
    4. Add disableValidation configuration/property
    5. Logic for disableValidation will be in validate so that when it is off; it is completely off.

    We welcome any feedback that you guys may have.

    Thanks,
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  10. #10
    Ext User Joe's Avatar
    Join Date
    Apr 2007
    Posts
    243
    Vote Rating
    0
    Joe is on a distinguished road

      0  

    Default With disableValidation turned off, can I still call validate?

    With disableValidation turned off, can I still call validate?


    Use Case:
    I want to disable validation on all fields so there are no red boxes. Once the user attempts to submit the form and it fail - I turn validation on for the fields (on blur). This way when they update the fields, it clears the red boxes.

    I may be able to handle this use case with disableValidation implemented .. do you have proposed code updates to test with?

    I am actually hooking into the validation routine .. like some of the advanced xtype sample pages do .. which makes it a bit tricky .. that is why I would like to see / try some code to see if it fits the bill.
    Joseph Francis,
    CoreLan / Meeting Consultants