XWidgetSoft Forum

XWidget & XLaunchpad , Desktop customization
It is currently 2018年 Feb 20日 13:32

All times are UTC - 8 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: 2017年 Apr 20日 06:14 
User avatar

Joined: 2013年 Jul 29日 09:13
Posts: 587
Question for you lot here re: dialogs.
When opening a file open dialog box, is there a method to add a file filter to the input of the dialog function?

I want to do something like this:

var validTypes = [".mpeg",".mp4",".m4a",".mpg",".flv","*.mp3",".aac",".wav",".wma",".aif",".aiff",".au",".snd"];

        fileName = openFileDialog(validTypes);

but it is unclear to me how a traditional filter works with the xwidget dialogs.

The standard way of doing it, if it was a Microsoft dialog box would be:
openFileDialog.filter= ".mpeg",".mp4",".m4a",".mpg",".flv","*.mp3",".aac",".wav",".wma",".aif",".aiff",".au",".snd"; 
but this does not seem to work.

Instead, I am using a filter function on the returned (output) value as follows:

var validTypes = ["mpeg","mp4","m4a","mpg","flv","mp3","aac","wav","wma","aif","aiff","au","snd"];

        fileName = openFileDialog("");

        if (validate_fileupload(fileName) === true ) {
        } else {
          alert("incompatible file type");

function validate_fileupload(fileName)
    var allowed_extensions = validTypes;
    var file_extension = fileName.split('.').pop();
    for(var i = 0; i < allowed_extensions.length; i++)
            return true; // valid file extension
    return false;

This does the job but it is not the most elegant approach and so I ask: Is there a better method of adding an input filter to a file open dialog?

Documentation for xwidget is sparse as always and the inline documentation shows little as reference, so please help. It would be nice to know, then I could add it to a tutorial I am writing.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours

Who is online

Users browsing this forum: No registered users and 7 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group