Mandatory Depends not applied when using bulk edit

Hi,

I have custom DocType

In some fields I have set the “Mandatory Depends On (JS)”, and is working correctly.

When I am in List View form for the DocType, if I use the Action button > Edit,

I can edit/save the doctype bypassing any Mandatory rule.

Just to give an example: if the field “Result” = Error, then field “Note” is mandatory because user must describe why there is an error.

If I use Action > Edit and I set Result field = Error, it allow me to save with Note field empty.

How can I force to use my mandatory rules also when using bulk edit?

Thanks

The “Mandatory Depends On” is client-side only and is bypassed in List View bulk edit. Fix it by adding server-side validation in your DocType’s Python controller:

def validate(self):
If self.result == “Error” and not self.note:
frappe.throw(“Note is mandatory when Result is Error.”)

This enforces the rule everywhere — form view, list edit, API, etc.

2 Likes

Hi,

as I never worked since now with server-side, can I put this code in a Server Script (from Frappe UI) or I need to manually put in the .py file of the doctype?

Thanks

You can use a Server Script from the Frappe UI no need to touch any .py files.

Go to Server Script → New and set:

  • Script Type: DocType Event
  • DocType: your DocType name
  • DocType Event: Before Save

Then add this code:

if doc.result == “Error” and not doc.note:
frappe.throw(“Note is mandatory when Result is Error.”)

That’s it — works immediately and enforces the rule everywhere.

Tested, it works perfectly!

Thanks

1 Like