How to: Exclusive OR for a mandatory choice?

Suppose I have three DocTypes:

  • Widget
  • FooBar
  • Controller

In Controller I have three fields:

  1. a check box : is_a_widget
  2. a table link to Widget (mandatory)
  3. a table link to Foobar (mandatory)

If is_a_widget = 1 then selecting a Widget is mandatory and Foobar is disabled
If is_a_widget = 0 then selecting a Foobar is mandatory and Widget is disabled

After Submit the is_a_widget check mark and only one of the fields should be visible. All should be read-only.

Is this even possible?

Everything I try seems to get me the error:

Invalid Mandatory Depends On condition

1 Like

Could we see the DocType definition (json file)?

"depends_on": "eval: doc.is_a_widget == false", (or true, depending on where this is going)

Iā€™m assuming you have a line similar to this one above on both the Widget and Foobar table fields?

1 Like

Ironically, I just ran into something similar. The mandatory means the field is occupied, no matter what.

My scrappy solution was to not make the fields mandatory and use set_df_property in the JavaScript instead. As the form is loaded, refreshed, and changed, the JavaScript will do the following on my field:

frm.set_df_property('myfield', 'reqd', 0); // I'm assuming 'reqd' means "required".

Along with a frappe.throw on form validation to show an error, this is the best I could do. Keep in mind this only works if editing documents through the normal Frappe DocForm.

Iā€™m still experimenting. :frowning:

(My original error was thinking the condition was described in SQL, so I was using single ā€œ=ā€. Your example made me wake up. Thanks for that.)

This is weird. So ERPNext provides a great big expandable text box ā€œMandatory Depends Onā€ so you can enter very detailed conditions that will never have any effect 'coz the field will always be mandatory anyway? Reminds me of Kurt Vonnegutā€™s troop ship to Neptune, where the cockpit has only a big red STOP button ā€¦ so the troops ā€œfeelā€ like theyā€™re still in control.

I was thinking that that would be the case if the database table attribute was defined as ā€œNOT NULLā€, but I checked and it isnā€™t.

Oh for fā€™sake!!!

https://github.com/frappe/frappe/issues/10259

My learning path for ERPNext has simply taken me from bug to the next bug to another bug. Wasting time and more time and yet more time. Itā€™s a mine field! It really is!

For what itā€™s worth :

I didnā€™t even know there was a Mandatory Depends On field. Iā€™m still developing on v12 :sweat_smile:

OH! Well that clarifies things ā€¦ a little bit!

Iā€™m working on commissioning my first ERP site, and reckon by going for Ubuntu 20.04 LTS and ERPNext v13 I ought to get a couple of years run before having to face upgrading. But, then the down-side of a brand new platform is the lack of guard rails, right?.

Iā€™ll be using :

1 Like