Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to disable Settings #8

Closed
jjspace opened this issue Dec 27, 2020 · 5 comments
Closed

Ability to disable Settings #8

jjspace opened this issue Dec 27, 2020 · 5 comments

Comments

@jjspace
Copy link

jjspace commented Dec 27, 2020

It would be great to be able to disable specific settings. For example if two toggle settings are "linked" so that the second only applies if the first is enabled. It would be great to be able to show both settings so the user understands that they both exist but have the second disabled (visually and functionally) so they can't click it without enabling the other one first.

I'm picturing something like this:

// ... in display() of PluginSettings
const setting1 = new Setting(containerEl)
  .setName('First setting')
  .setDescription('enable something and allow second setting to be set')
  .addToggle((toggle) => toggle.setValue(this.plugin.settings.firstOpt).onChange(async(value) => {
    this.plugin.settings.firstOpt = value
    await this.plugin.saveSettings();
    if (value) {
      setting2.enable()
    }
    else {
      this.plugin.settings.secondOpt = false;
      setting2.disable()
    }
  }))

const setting2 = new Setting(containerEl)
  .setName('Second setting')
  .setDescription('Enable something else. only enabled when firstOpt is on')
  .addToggle((toggle) => toggle.setValue(this.plugin.settings.secondOpt).onChange(async(value) => {
    this.plugin.settings.secondOpt = value;
    await this.plugin.saveSettings();
  }))
if (this.Plugin.settings.firstOpt) {
  setting2.disable()
}
@lishid
Copy link
Collaborator

lishid commented Dec 27, 2020

I think I understand your use case, for now you'll have to manually disable the control elements, and possibly add some styles to the entire line to be more explicit.

One thing I'd like to note is that Setting don't keep track of its internal controls at the moment, which makes it a bit more difficult. Right now, we don't currently have such a need yet, but when we do it won't be too hard to add.

@jjspace
Copy link
Author

jjspace commented Dec 27, 2020

you'll have to manually disable the control elements

That's kinda what I ended up doing. However because of the way inputs are set up (the toggle specifically) there is no way to actually disable, remove or block the click handler. The best I could come up with is adding the css: pointer-events: none;. As a web dev myself this is a terrible way to disable an input, if it's the only one implemented, which is why I created the request for an internal option.

Hopefully we can get something like this in the future!

@lishid
Copy link
Collaborator

lishid commented Dec 27, 2020

Ah I see what you mean. That's definitely a problem.

@lishid
Copy link
Collaborator

lishid commented Feb 23, 2021

setDisabled is now available on Setting and Component. I totally forgot to comment here but it's been in for a few releases already.

@lishid lishid closed this as completed Feb 23, 2021
@jjspace
Copy link
Author

jjspace commented Feb 23, 2021

@lishid Oh awesome! Thanks for adding that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants