Mix display and required logic for custom fields

Cheers!

I am trying to mix required and display logic on the same custom field logic. The condition is simple if field X has a certain value set then field Y becomes visible and also required. Otherwise field Y is not visible and not required.

Independently each custom logic works but when i use them together only visibility logic works but not the required. Any ideas?

Thanks!

The following code works for me. I have department field in contacts module and the department becomes visible and required when I set the title as ‘Manager’.
We need to have to logic types ‘required’ and ‘displayType’ as shown in the example.

Could you please try the code for your fields and see it helps.

   1 =>
	array(
		'name' => 'department',
		'label' => 'LBL_DEPARTMENT',
		'display' => 'none',
		 'logic' => [
					 'hide-show-dept' => [
					 'key' => 'displayType',
					 'modes' => ['create','edit'],
					 'params' => [
						 'fieldDependencies' => ['title'],
						 'targetDisplayType' => 'show',
						 'activeOnFields' => [
							 'title' => ['Manager'],
						 ],
					 ],
				 ],
					 'dept-required' => [
					  'key' => 'required',
					  'modes' => ['create','edit'],
					  'params' => [
						  'fieldDependencies' => ['title'],
						  'activeOnFields' => [
							 'title' => ['Manager'],
						  ],
					  ],
				 ],
		 ],
	),

Run php bin/console cache:clear and realod the application to test.

This works thank you!!

The key moment I have been missing, I think, is setting it as hidden to begin with:

'display' => 'none',