Art F
Art F

Reputation: 4202

In ExtJS, event fired before clicking opening a file upload field

I have Ext.form.field.File, with the buttonOnly attribute set to true. My question is, is there any event I can execute after I press the 'browse' button but before the file selector pops-up. I want the selector not to pop-up in certain conditions that I want to check. Any advice? I tried show and keydown. Both of which didn't execute.

Upvotes: 1

Views: 2358

Answers (1)

lontivero
lontivero

Reputation: 5275

Yes, it is a little tricky but is what you are looking for:

var file =Ext.create('Ext.form.field.File', {
        name: 'photo',
        fieldLabel: 'Photo',
        labelWidth: 50,
        msgTarget: 'side',
        allowBlank: false,
        anchor: '100%',
        buttonText: 'Select Photo...',
        renderTo:Ext.getBody(),
});

file.mon(file.triggerWrap, {
    click : function(){ 
        alert('yes you can'); 
        file.disable();
        Ext.defer(function(){file.enable();}, 10);        
    }
});​

disable() method is used to prevent raising other events (which will prevent open the popup for selecting the file)

Here you have the working example: http://jsfiddle.net/lontivero/GmAUt/2/

Upvotes: 1

Related Questions