Home    |    GitHub Page    |    API    |    FAQ

How to create dropdown in plugin settings?

I'm currently trying to create a dropdown option (enum) within the plugin settings. But all I get is an empty select button:

image

Here's the code I've tried:

    await SETTINGS.registerSetting('unpinBehavior', {
      value: 'KEEP_SELECTED',
      type: SettingItemType.String,
      section: 'note.tabs.settings',
      isEnum: true,
      public: true,
      label: 'Select unpin behavior',
      options: () => {
        // 1 how it is used in the app - doesn't work
        return {
          keep: 'KEEP_SELECTED',
          last: 'SELECT_LAST_ACTIVE',
          adjacent: 'SELECT_ADJACENT',
        };
        // 2: simple array - doesn't work
        // return ['KEEP_SELECTED','SELECT_LAST_ACTIVE', 'SELECT_ADJACENT'];
        // 3: simple string - doesn't work
        // return 'KEEP_SELECTED';
      }
    });

I've copied the code from the App settings below:

newTodoFocus: {
      value: 'title',
      type: SettingItemType.String,
      section: 'note',
      isEnum: true,
      public: true,
      appTypes: ['desktop'],
      label: () => _('When creating a new to-do:'),
      options: () => {
        return {
          title: _('Focus title'),
          body: _('Focus body'),
        };
      },
    },

Does anyone has an idea what I'm doing wrong? Or is not yet supported correctly?

Thanks.

1 Like

I don't think plugins have this.I was also looking for it but settled for boolean.

Did you try as an object?

options: {
	keep: 'KEEP_SELECTED',
	last: 'SELECT_LAST_ACTIVE',
	adjacent: 'SELECT_ADJACENT',
}

Otherwise it means it's not working and would need to be fixed.

Seems also not to work. I get the following error when opening the settings view:

Error
Joplin encountered a fatal error and could not continue. To report the error, please copy the *entire content* of this page and post it on Joplin forum or GitHub.

Message
md.options is not a function

Version info
Joplin for Desktop

Copyright © 2016-2021 Laurent Cozic
Joplin 1.6.6 (dev, win32)

Client ID: e8cd6740a96d4da78f033fac4ae93de1
Sync Version: 2
Profile Version: 34
Keychain Supported: Yes

Revision: f58b7563e (master)
Stack trace
TypeError: md.options is not a function
    at ConfigScreenComponent.settingToComponent (C:\Program Files\Joplin\resources\app.asar\gui\ConfigScreen\ConfigScreen.js:331:39)
    at createSettingComponents (C:\Program Files\Joplin\resources\app.asar\gui\ConfigScreen\ConfigScreen.js:144:42)
    at ConfigScreenComponent.sectionToComponent (C:\Program Files\Joplin\resources\app.asar\gui\ConfigScreen\ConfigScreen.js:149:30)
    at Object.shared.settingsToComponents2 (C:\Program Files\Joplin\resources\app.asar\node_modules\@joplin\lib\components\shared\config-shared.js:184:28)
    at ConfigScreenComponent.render (C:\Program Files\Joplin\resources\app.asar\gui\ConfigScreen\ConfigScreen.js:528:37)
    at finishClassComponent (C:\Program Files\Joplin\resources\app.asar\node_modules\react-dom\cjs\react-dom.development.js:17039:31)
    at updateClassComponent (C:\Program Files\Joplin\resources\app.asar\node_modules\react-dom\cjs\react-dom.development.js:16994:24)
    at beginWork$1 (C:\Program Files\Joplin\resources\app.asar\node_modules\react-dom\cjs\react-dom.development.js:18505:16)
    at HTMLUnknownElement.callCallback (C:\Program Files\Joplin\resources\app.asar\node_modules\react-dom\cjs\react-dom.development.js:347:14)
    at Object.invokeGuardedCallbackDev (C:\Program Files\Joplin\resources\app.asar\node_modules\react-dom\cjs\react-dom.development.js:397:16)
Component stack

    in ConfigScreenComponent (created by Connect(ConfigScreenComponent))
    in Connect(ConfigScreenComponent) (created by NavigatorComponent)
    in div (created by NavigatorComponent)
    in NavigatorComponent (created by Connect(NavigatorComponent))
    in Connect(NavigatorComponent) (created by RootComponent)
    in ThemeProvider (created by RootComponent)
    in StyleSheetManager (created by RootComponent)
    in RootComponent (created by Connect(RootComponent))
    in Connect(RootComponent)
    in ErrorBoundary
    in Provider
1 Like

That will be fixed in next pre-release, and syntax will be like so:

await joplin.settings.registerSetting('multiOptionTest', {
	value: 'en',
	type: SettingItemType.String,
	section: 'myCustomSection',
	isEnum: true,
	public: true,
	label: 'Multi-options test',
	options: {
		'en': 'English',
		'fr': 'French',
		'es': 'Spanish',
	},
});
2 Likes