Currently it appears that the module applies the first state condition, not each multiple state condition, when more than one is configured.

In my use case I have three options in a select list in field x and field y is configured to be required AND visible if field x is set to option 1. When field x is set to either option 2 or 3 the field is no longer required, as that state comes first, but is still visible.

If I remove the required state condition, the visibility condition works as intended.

Comments

ryan.ryan’s picture

Category: Feature request » Bug report

This happens for me as well. And as they're separate settings that can be added in the UI without overwriting the other, it seems more appropriately categorized as a bug.

drupalove’s picture

Edit: Please ignore my comment as I was confused with another module.
When the condition is set to 'Value' and the form state is set to 'Required' in this case you will not get the Show/Hide option. Therefore field y will always be visible which I think is a normal behaviour. This module provides visibility settings via the Show/Hide effect option which is available only if you select visible or invisible.
It is possible to add Show/Hide effect when 'Required' is selected but I don't think the module was intended to do this.
You can achieve what you want by setting the form state of field x to 'Visible' and making field y required. Please correct me if I'm wrong.

kopeboy’s picture

What if I have:

  • Customer type: (radio) list: company or individual
  • Company name: text
  • Full name: text

and I want:

  • if Customer type = company -> Company name is required AND Full name is invisible
  • if Customer type = individual -> Full name is required AND Company name is invisible

Came here from Conditional Fields because they seem to support this, but the required/optional part doesn't work (at least on Commerce>CustomerProfile>Billing)

drupalove’s picture

@kopeboy yours is a different issue. See #2222659: Add support for "Check boxes/radio buttons" widget.

Until that issue is resolved you can achieve what you want with the select list widget.

chrisrockwell’s picture

Title: Multiple states on single target » Can not use visible/invisible if using any other state type
Version: 7.x-2.1 » 7.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new643 bytes

Updating title to be more accurate.

_field_conditional_state_add_direct_states defines states that are added after visible/invisible are added. However, _field_conditional_state_build_states_array resets $element['#states'].

The attached patch allows for existing states.

greenstick’s picture

Thanks Chris! Patch worked for me and was sorely needed. (I should note I changed it manually here on Windows/WAMP since I don't have a patching utility handy so I can't attest to the .patch file so much as the code changes referenced therein.)

Anyway, totally did the trick.

welly’s picture

Status: Needs review » Reviewed & tested by the community

Works for me too. Just tested. Nice patch, thank you.