How can I (either with a module or programmatically) limit the number of values for multiple fields? For example, the user can add only a single value for field A OR field B OR field C. The total maximum number of values behind all fields can't exceed 1.
Using a contrib module: You can use the conditional_fields module.
Doing it programatically:
You can use the
#states property in a custom form or
You must add this to field A, B and C:
'#states' => [ 'invisible' => [ [':input[name="field-name"]' => ['filled' => TRUE]], 'or', [':input[name="field-name-2"]' => ['filled => TRUE]], ], ],
Of course you have to replace "field-name" and "field-name-2" with the two field names that are not the one adding the states to, hope it makes sense.
If you can’t find the name of the field you can look in the browser inspector to get the name of the input field.