runOnAttributeChange is not triggered in "Quick edit" #7888
DescriptionSteps to reproduce:
api.runOnFrontend(function() {
const noteId = api.getActiveContextNote().noteId;
api.runOnBackend(function(frontendNoteId) {
const note = api.getNote(frontendNoteId);
const category = note.getLabelValue("mycategory");
if (category === "Health") {
note.setLabel("color", "green");
} else {
note.removeLabel("color");
}
}, [noteId]);
}, []);
If you followed the steps above you will notice the "Visit dentist" note did not change its color to green. However, if you open "Visit dentist" in a new tab, new split, or new window and set the I suspect this is TriliumNext Version0.99.5 What operating system are you using?Other Linux What is your setup?Local + server sync Operating System VersionArch Linux x86_64 (Linux 6.17.9-arch1-1) Error logsNo errors showing up in the backend logs or the frontend console |
Replies: 2 comments 1 reply
|
Hi @bglogic! I'm Dosu and I’m helping the Trilium team. You're right— To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
|
Hi, This is not a bug, per se.
Although I don't see documented anywhere, there is this magic Using const attr = api.originEntity;
if (attr.name !== "mycategory") return;
const note = api.getNote(attr.noteId);
if (attr.value === "Health") {
note.setLabel("color", "green");
} else {
note.removeLabel("color");
} |
Hi,
This is not a bug, per se.
runOnAttributeChangeis actually executed in Quick Edit as well. You can confirm this by doing aconsole.log(orapi.log) inside the frontend part of the script. The reason is thatrunOnAttributeChangeis actually not related to the UI/client at all, since everything is run on the server.api.getActiveContextNote(). The active note context always represents the active tab. Even if there is a quick edit popup open, it will still return the currently active tab (which in your case happens to be the board).Although I don't see documented anywhere, there is this magic
api.originEntityproperty which is populated automatical…