neutralinojs

neutralinojs workaround to HTML input attribute accept


I have a neutralinojs app with an file input. It should only be possible to choose files from type ".csv" or ".xlsx". So I use the accept attribute.

<input type="file" accept=".csv,.xlsx" />

That works in browser mode but not in window mode.

Is there a workaround to show only files with these filetypes in the file chooser?


Solution

  • You Need To Use Neutralino's API For Dialogs.

    So In Neutralino's OS API We Have Some Functions For save file, open file and open folder using which we can show dialogs to users.

    In your case you need to use open file dialog so you can use Neutralino.os.showOpenDialog, example:

    Neutralino.os.showOpenDialog('Open a file', {
      filters: [
        {name: 'Documents', extensions: ['csv', 'xlsx']},
        {name: 'All files', extensions: ['*']}
      ]
    }).then(result => {
      console.log('You have selected:', result);
    });
    

    One thing to note is all these API will work in both modes, browser and window.

    So if you run this code in browser mode a dialog box will still appear.

    Read More About Neutralino's OS APIs