How to hide .form-assignments section for all doctypes using plain JS in doctype_js hook?

Hi everyone,

I’m trying to hide the “Assigned To” section (.form-assignments class) on all doctypes using plain JavaScript. I’ve added a global JS file using the doctype_js hook in hooks.py like this:

doctype_js = { "*": "public/js/doctype.js" }
In that file, I tried the following:

js

frappe.ui.form.on('*', {
    onload: function () {
        const interval = setInterval(() => {
            const assignmentSection = document.querySelector(".form-assignments");
            if (assignmentSection) {
                assignmentSection.style.display = "none";
                clearInterval(interval);
            }
        }, 300);
    }
});

But nothing works — the assignment section is still visible.

What I tried:

  • Ensured the path to the JS file is correct.

  • Tried both onload and refresh events.

  • Tried DOMContentLoaded and setTimeout approaches.

  • Cleared cache using bench clear-cache and Ctrl + Shift + R.

  • Environment:

Frappe version: 15

Custom app with doctype_js hook targeting “*”.

Question:

What is the correct way to hide the .form-assignments section globally (for all doctypes)?

Any help would be appreciated — thank you :pray:

Is there a reason you’re trying to do this via javascript instead of css? Perhaps I’m misunderstanding your goals, but couldn’t you just make a rule like

.form-assignments { display: none; }

and be done with it?

@peterg
I want to hide it for specific roles

I would still try injecting CSS, rather than this complicated interval stuff. I don’t know specifically why your script isn’t working, but it’s pretty fragile to write it this way. If the .form-assignment elements get rewritten after onload, for example, your display value will be removed.