1. #1
    Ext User
    Join Date
    Feb 2008
    Posts
    33
    Vote Rating
    0
    Crisps is on a distinguished road

      0  

    Question [SOLVED]File TextField - validation event issue

    [SOLVED]File TextField - validation event issue


    I have a file text field defined as follows

    Code:
     this.field_data 	= new Ext.form.TextField({renderTo: 'datafile',
    								name: 'uploadedfile', 
    								allowBlank: false,
    								invalidClass: '',
    								inputType: 'file',
    								width: 75
    							});
    										
    				this.field_data.on('valid', this.on_data_valid, this);
    				this.field_data.on('invalid', this.on_data_invalid, this);
    I need to fire a handler, when the value of the edit box is changed. This needs to be immediately, before the blur.

    This all works fine on a normal TextField because you are usually typing into the box, so the keyup/down/press events can be used to fire off validation etc. However with a file input box the user always uses the mouse to select the file they want so the handler never gets fired until the focus is lost and I need the handler to act before this point.

    The 'change' event has exactly the same problem of having to wait until after the blur.

    Does anyone know how to get around this problem?

    Thanks

  2. #2
    Ext User
    Join Date
    Feb 2008
    Posts
    33
    Vote Rating
    0
    Crisps is on a distinguished road

      0  

    Red face [SOLVED] File TextField - validation event issue

    [SOLVED] File TextField - validation event issue


    I have managed to solve my own problem here :-)

    When the field dialog opens the selection window it loses focus because it is modal. When you dismiss the selection dialog for any reason then you refocus the text window. You can then use this event to perform the validation.

    Code:
    		this.field_data 	= new Ext.form.TextField({renderTo: 'datafile-',
    									name: 'uploadedfile', 
    									allowBlank: false,
    									invalidClass: '',
    									inputType: 'file',
    									width: 75
    								});
    										
    		this.field_data.on('valid', this.on_data_valid, this);
    		this.field_data.on('invalid', this.on_data_invalid, this);
    		this.field_data.on('focus', this.on_data_focus, this);
    	},
    	
    	on_data_valid: function(field)
    	{	
    		//do stuff on valid
    	},
    
    	on_data_invalid: function(field)
    	{	
    		//do stuff on invalid
    	},
    	
    	on_data_focus: function(field)
    	{
    		this.field_data.validate.bind(this.field_data).defer(100);
    	},
    The focus handler is called before the file name is copied from the selection dialog. Because of this we must defer the validation slightly. I am using the prototype adapter for bind and defer, there should be something similar in ExtJS proper too though.

    This works fine in both Firefox 3.5 and IE 8, hopefully it will work with all browers.

    I hope this helps others who are stuck with the same issue.

Similar Threads

  1. Event on Textfield type file
    By couetbis in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 5 Oct 2009, 1:41 AM
  2. Replies: 1
    Last Post: 13 Jul 2009, 12:18 PM
  3. Validation for inputType: 'file' textfield
    By tomlobato in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 10 Jul 2009, 10:46 AM
  4. TextField Validation - Validation Fired as soon as user clicks into Field - bug?
    By jfisher in forum Ext GWT: Help & Discussion (1.x)
    Replies: 0
    Last Post: 29 Sep 2008, 9:25 AM
  5. "change" event at textfield with "file" type
    By RobertoCavali in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 12 Jul 2008, 5:01 AM

Tags for this Thread

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