Disable mandatory lookup field that inherts from a parient lookup field

Disable mandatory lookup field that inherts from a parient lookup field

Hello,


I have three lookup fields, a parent, a child, and a grandchild. I made the parent and the child mandatory, the grandchild needs to be mandatory only when its values are available and that is not always the case, hence why I disabled the mandatory checkbox. Eventually, the selection of the higher level field will determine the lower one values obviously.

For a more specific description: A parent can have one or more children, and a child can have one or more grandchildren.


Since I disabled the mandatory checkbox, I'm trying to write a script in Deluge on the submit form moment, so that when the child lookup field has grandchildren then I can prevent submit. 

Any advice on how to do this would be highly appreciated.