Carbon-fields: Conditional logic based on Set field

Created on 12 May 2017  路  5Comments  路  Source: htmlburger/carbon-fields

I am trying to create a field that is conditional on the options selected in a Set field.

$fields = array(
    Field::make( 'set', 'types' )->set_options( $post_types ),
);
foreach ( $post_types as $key => $name ) {
    $fields = array_merge( $fields, array(
        Field::make( 'relationship', 'type' . $key . '_selector', html_entity_decode( $name ) . ' Projects' )
             ->set_conditional_logic( array(
                 array( 'field' => 'types', 'value' => $key, 'compare' => '=' ),
             ) )
             ->set_required( true ),
    ) );
}

With this code, if I select one item in my Set, it shows the correct associated conditional field. However i I select more than one item in the Set, none of my conditional fields show. I have also tried using the IN compare operator

[type] bug

Most helpful comment

Thanks for your reply :) Honestly, I meant to post my comment in this exact ticket because today I've stumbled upon this problem myself, found the ticket and saw that you posted a solution only 11 days after the original post. And since this has happened several times since using Carbon Fields I just had to thank you right away ;)

Thanks again, I will be going back now to enjoying using Carbon Fields and spreading the word :)

All 5 comments

Thanks for the report, @Santana1053 . We'll post an update when we have the chance to investigate the issue.

1.6 has just been released which addresses this situation with the new INCLUDES and EXCLUDES comparison operators.

In your case, the definition should be updated as follows:

->set_conditional_logic( array(
    array(
        'field' => 'types',
        'value' => $key,
        'compare' => 'INCLUDES'
    ),
) )

@atanas-angelov-dev I think it is really amazing how quickly you respond to issues like this one. Thanks a lot for your efforts! Is there any way we can support you or show our appreciation?

@gardiner spreading the word and what you enjoy about Carbon Fields is plenty support for us : )

PS:
I assume you meant to post this in another ticket since this one is from May?

Thanks for your reply :) Honestly, I meant to post my comment in this exact ticket because today I've stumbled upon this problem myself, found the ticket and saw that you posted a solution only 11 days after the original post. And since this has happened several times since using Carbon Fields I just had to thank you right away ;)

Thanks again, I will be going back now to enjoying using Carbon Fields and spreading the word :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MDSilviu picture MDSilviu  路  3Comments

jquimera picture jquimera  路  4Comments

halvardos picture halvardos  路  4Comments

olegburakov picture olegburakov  路  3Comments

jonwaldstein picture jonwaldstein  路  3Comments