Hi guys,
im new to obsidian api dev. So please forgive me my nobness
I have used and implemented the “Sample Plugin” from the Obsidian api Repo. And now I was trying to add a new Setting to my plugin (A Dropdownmenu with 2 options). But somehow it cant save the selection being made, when in the plugin settings. For example: I switch to another plugin settings tab, and when I switch back, the selection being made in the dropdown is not shown. I checked the console. It says no errors whatsoever, so I think it’s a UI issue, but I am not sure. Here are parts of my code used in the main.ts from the Sample-Plugin:
interface MyPluginSettings {
repetitions: string;
}
const DEFAULT_SETTINGS: MyPluginSettings = {
repetitions: '1'
}
//later in the main.ts:
class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin;
constructor(app: App, plugin: MyPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
let {containerEl} = this;
containerEl.empty();
containerEl.createEl('h2', {text: 'Full-Repetition Settings'});
new Setting(containerEl)
.setName('Number of repetitions')
.setDesc('Here you can set your default number for repetition reminders')
.addDropdown(dropDown => {
dropDown.addOption('1', '1 Repetition');
dropDown.addOption('2', '2 Repetitions');
dropDown.onChange(async (value) => {
this.plugin.settings.repetitions = value;
await this.plugin.saveSettings();
});
});
}
}
Could someone tell me, what I did wrong?
Thanks for the help in advance!