Field required but only if condition is true

Hello,

I’m experiencing an issue since I’m working with Cockpit : if a field is set to required and has a condition, if the condition is not set, the field will prevent the form submission.

Example : I have an asset field “banner_asset” which has a condition : data.banner_has_asset == true

If “banner_asset” is false, the field won’t be shown (logic) but, I won’t be able to submit my new collection entry, because “Field “banner_asset” required”.

How to make my “banner_asset” field required ONLY if its condition is set ?

Ok to do so, we just have to modify the following file :

cockpit/modules/System/assets/vue-components/fields/renderer.js

Add on line 372:

this.fields.forEach(field => {

//add this
if (!this.checkFieldCondition(field)) {
	return;
}
//end

...

So now, the field will be required only if its condition is true.