2

I am new to Ext JS4. What i would like to achieve is to open a file dialog from a menu.

I know if i create it as a button as shown below and add it into the menu as an item it will work. But i do not wish to add it as a button in the menu.

var importButton = Ext.create('Ext.form.file.File', {
   buttonOnly: true,
   buttonText: 'Import',
   hideLabel: true,
   listeners: {
      'change': function(fb, v){
              onImportButtonClick(fb.getValue());
            }
   }
});

The below is the code that i have.

var fileMenu = Ext.create('Ext.menu.Menu', {
   width: 125,
   maxWidth: 125,
   padding: 0,
   plain: false,
   items: {
      text: 'Import',
      id: 'import',
      handler: function(){
           //Code to open up the file dialog
      }
    }
});

Hope someone out there could guide me on how to fill out the commented part. Many thanks in advanced.

Nivek
  • 719
  • 4
  • 15
  • 27
  • 2
    May I ask why do you not wanna make the button as a real button? Don't take me wrong, but that's the point of the Button. If you manage to do that with the menu component, either you are gonna have to encapsulate that within a new component, or you are gonna have some serious hacking going on in your code. – Daniel Ribeiro Mar 15 '12 at 11:36
  • Is just something personal that i feel it looks weird having a button on a menu. I was hoping is just some config that i need to set to have to file dialog incorporated into the menu. If some serious hacking and slashing is needed, then i think i will just live with the buttons.. LOL Thanks anyway – Nivek Mar 16 '12 at 07:16
  • It's a security restriction imposed by the browser that only by clicking on the file input component will the file open dialog be shown. – Rene Saarsoo Mar 16 '12 at 12:28

2 Answers2

0

I think you can find the answer here open file dialog box in javascript

Usually I find this a good way to customize some "file upload" menus on file sharing sites.

Community
  • 1
  • 1
U and me
  • 730
  • 5
  • 13
0

use PLUpload

you can then upload multiple files if you want, resize images on the client, and display your upload 'button' any way you want

Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152