What is the correct syntax for Mandatory Depends On

I have two fields:

  1. requires_widget : Checkbox
  2. necessary_widget : Link ==> Item

If requires_widget is checked then necessary_widget must link to a valid Item

In the text area “Mandatory Depends On” of necessary_widget I put:

requires_widget === true;

Also I checked the Mandatory checkbox.

The result is that the necessary_widget field is always mandatory.

I’d be grateful for any hint of what I am missing.

eval:doc.requires_widget

2 Likes

At last I understand!

There is a checkbox Mandatory. It means what it says.

There is a text field Mandatory Depends On that does NOT mean what is says at all.

The Mandatory condition does not ever depend on the text field contents.

Accurate, unambiguous nomenclature for Mandatory Depends On would be Conditional Mandatory Dependency.

User-friendly nomenclature for Mandatory would be Unconditional Mandatory.

good idea, maybe it can be set as description.
:+1:

Definitely a more-accurate name.

More thoughts on this topic:

Recently, I had to add a second “mandatory” flag to DocField: 'Mandatory only in DB'.

The challenge with ‘Mandatory’ is that it enforces mandatory values in both frontend JavaScript, and backend Python. :thinking:

I wanted to enforce a value in the database. But I didn’t care if the User entered a value on the web page. If they did, I’d accept it. But otherwise, a value is automatically assigned in the Document’s 'before_validate()' function.

2 Likes

Curious to know … have you submitted a pull request?

Do you really think the dev team would want to include something like this?!?

It seems to be a very specific use case and would require a great deal more knowledge of how to use it than the average user base.

Sometimes you do something for a specific client need and let it work for a while before you consider if it has value to the core system. And sometimes the hurdles to jump for a PR are just not available in your calendar.

Just my opinion… (and you know what they say about opinions). :thinking:

BKM

True. I was not thinking along those lines.

Instead, I was thinking about all the tremendous value invested in tweaks to core software that never make it into the code base and. possibly, get reinvented dozens of times.

How could we capture all that?

1 Like

My opinion, since it is just a label naming, there is no harm submitting a PR. You don’t have to maintain it anyway. Submit and pray :slight_smile:

I have not.

I am happy to find the related code snippets, and share them here (it’s only a few lines of Python) if this is something you’d want to have.

An excellent question, and one I often think about. I do not have a solution.

Some people are comfortable with submit and pray. I am not one of those people.

1 Like

Thanks for the offer. It did strike me as useful, but I don’t have an immediate need.

IMO, you should file an issue or even add a PR for this.

This is NOT a rare edge case.

Requiring a value, but if none is given, trying to default to something else, otherwise throw a validation error – this strategy is used in several Frappe and ERPNext core doctypes, so even Core would profit from a “Mandatory only in DB“ feature.

Regards.