XWidgetSoft Forum https://www.bbs.xwidget.com/ |
|
HELP: open file dialog with filter https://www.bbs.xwidget.com/viewtopic.php?f=7&t=6655 |
Page 1 of 1 |
Author: | yereverluvinuncleber [ April 20th, 2017, 6:14 am ] |
Post subject: | HELP: open file dialog with filter |
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: Code: 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: Code: 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: Code: var validTypes = ["mpeg","mp4","m4a","mpg","flv","mp3","aac","wav","wma","aif","aiff","au","snd"]; fileName = openFileDialog(""); if (validate_fileupload(fileName) === true ) { PlayFile(fileName); } 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++) { if(allowed_extensions[i]==file_extension) { 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. |
Page 1 of 1 | All times are UTC - 8 hours |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |