I started working with the new declarative settings API. I created a list of sub-pages. Every sub-page has a user defined name. Now my naive approach to renaming was a text field on each sub-page. But since the name also is the path of that sub-page, I run into the following problem:
If I run update(), the page I was on no longer exists. I stay on an empty sub-page with only the old name and the “back”-button in the header.
My goal would be to update the list on the main page and the name in the header of the open sub-page.
The only ideas I have don’t work or just aren’t good options:
Not running update() immediately
Ignores the “Save on change, not on submit”-convention
There is no “navigation”-event to listen on
refreshDomState() doesn’t help
Creating a rename modal
That just sounds way more confusing for users
If the modal is nested in the sub-page, I’d expect to end up with the same empty sub-page
If the modal is on the main-page, I need a “select existing sub-page”-dropdown. That sounds even worse
Triggering a navigation to the new sub-page
As far as I can see there is no API to trigger a navigation or even get the current path
Is there a good solution to this? Is there an intended way? Or is this a bug / missing feature?
If the path (or id of some sort) of the sub-page and the display name would be different things, I could keep the unique path/id the same and just change the display name. At least that would be the feature I would request, if there isn’t an existing solution.
Obsidian’s settings API doesn’t support separate display names, so the path always acts as the name. You could store a static ID in the metadata, then update that instead of renaming the file.
Sorry, but I dont’t understand your suggested solution. The name is used as a label for the sub-page button. So I can’t use an Id there. I could wait with the change until leaving the sub-page, but that isn’t really the intended way to save settings.
However I saw this in the changelogs for 1.14:
Settings: Added optional SettingDefinitionItem#id for setting a unique ID on individual settings. Think of it like <div key={key} /> in React. Use it to differentiate between sibling settings that share a name, or to keep a stable reference when a setting or setting page is renamed.
I haven’t tested yet, but this sounds exactly like what I needed.
Yes, the id field was added to fix this issue. Let me know if it solves your issue, and if you have any feedback on the API change. Thanks for your patience with getting this added.