Skip Navigation

[Resolved] CRED conditional OR behave like AND

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 14 replies, has 3 voices.

Last updated by davidZ-4 6 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#907211

I am trying to: create a or conditional display

Link to a page where the issue can be seen: hidden link

I expected to see: select option drop down after selecting 2 stage radio buttons i.e. select radio button in first option, render second radio buttons options, select second radio button display drop down select field,

Instead, I got: no display

i use the code below in my CRED form

<div class="form-group row column_3 imgcenter">
		
		[cred_field field='bike-type' post='rider-profile' value='' urlparam='' class='flex' output='bootstrap']
		
	</div>

[cred_show_group if="($(bike-type) eq  '1' )"  mode='fade']
	<div class="form-group row column_4">
      [cred_field field='road-bike-sub-cat' post='rider-profile' value='' urlparam='' output='bootstrap']
	</div>
[/cred_show_group]
[cred_show_group if="($(bike-type) eq  '2' )"  mode='fade-slide']
	<div class="form-group row column_4">
      [cred_field field='mountain-bikes-sub-cat' post='rider-profile' value='' urlparam='' output='bootstrap']
	</div>
[/cred_show_group]
[cred_show_group if="($(bike-type) eq  '3' )"  mode='fade-slide']
	<div class="form-group row column_4">
      [cred_field field='cityurbn-bikes-sub-cat' post='rider-profile' value='' urlparam='' output='bootstrap']
	</div>
[/cred_show_group]

<div class="row">

[cred_show_group if="($(road-bike-sub-cat) ne  '' ) OR ($(mountain-bikes-sub-cat) ne  '' ) OR ($(cityurbn-bikes-sub-cat) ne  '' )"  mode='fade-slide']
<div class="form-group col-md-4">
		<label>[wpml-string context='cred-form-My Rider Profile-86' name='I plan to ride']I plan to ride[/wpml-string]</label>
		[cred_field field='i-plan-to-ride' post='rider-profile' value='' urlparam='' select_text='--- not set ---' class='form-control' output='bootstrap']
	</div>
[/cred_show_group]

repro steps:
1. go to hidden link
2. select first option
3. second group of radio buttons render
4. select one of the alternatives
5. nothing happen
6. select another alternative from the first radio buttons group
7. new second group of radio buttons display
8. select one of the alternatives from the second group
9. nothing happen
10. select another alternative from the first radio buttons group
11. new second group of radio buttons display
12. select one of the alternatives from the second group
13. Select field drop down display

Please advise,
thanks,

David

#907354

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

I followed your steps and can see the same as you are describing.

The problem is I'm not completely sure what you *want* to happen.

Can you describe an example workflow of how it should work?

#907477

Hi Nigel,

here is what i would like to happen

1. user come to the page hidden link
2. click on one alternative
3. display the related sub alternatives
4. user click on one of the sub alternatives
5. display the drop down select list of "I plan to ride"

from there all the conditional display work just fine.

thanks,
David

#908517

Hi, Nigel is out today so he asked me to check in on his tickets. I see what you're describing, and I'm having some trouble getting the conditional to work exactly right myself. I'm escalating this issue to my 2nd tier support team for further investigation. It could be a bug, or it could be a limitation of the conditional engine. I will let you know as soon as I have some more information to share.

#908844

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

I'm back and took another look at this, and I can't reproduce the problem.

If you look at my screenshot you'll see that I have a radio field with choices alpha, beta, or gamma.

Depending on which of those is selected, a second field is displayed (alpha therefore, beta therefore, or gamma therefore). When one of those is chosen, a third field is exposed ("Arbitrary text").

I can navigate back and forth between the different fields and everything updates as expected.

Note that hiding a field because a prior selection has been changed does not reset the field.

So when I choose gamma and then make a Gamma Therefore choice, the final field is exposed, and is still visible if I switch to Beta Therefore because Gamma Therefore is not empty (even though I can no longer see it).

One thing I just noticed looking at your debug info is that you are using the current stable Views (2.6) and Toolset Forms (2.0), but you are not using the current Types (3.0).

Can you update to Types 3.0 and do some more testing?

(It looks like you updated to Types 2.3 on the main plugin page which took the 2.3 update from the WordPress plugin repo, rather than updating via the installer which would take the 3.0 version from our servers. We'll provide a way around this in a minor Types update, but in the meantime you can downloads Types 3.0 from wp-types.com/account/downloads and update it manually. You will likely need to delete 2.3 before you can upload 3.0, but won't lose any settings or data if you do.)

#908852

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

Quick update. I just double-checked something in the set-up, and the problem only occurs with radio fields.

I was just using a mix of select fields and radio fields when describing my test in the last reply, and realised your case uses purely radio fields.

With radio fields there is no initial state (a select field can have a "--please choose--" placeholder or similar when nothing is selected which radio fields do not have), and that is preventing a test such as yours from working.

I don't think it is currently possible. We have an internal ticket about something related but it is not yet resolved. I'm adding a comment about your use-case there so that the devs can give some feedback about it.

#909596

Hi Nigel,

thanks for the follow up.
I couldn't see any screenshots from your previews response so I Cant comment on your previews response.
I have updated type to 3.0 and i still have the same issue with the radio button.

also, i'm looking forward to hear what the dev team solution for this is.
thanks,

David

#911032

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

I just wanted to let you know that I spoke to the developers about this, and it is the case that the issue arises with radio fields when they are initially hidden because they have no initial value, unlike a select field.

It won't work currently.

They have in mind a possible solution, but it will take a little while to implement and publish an update.

I wanted to set your expectations: we'll try and make it work but you can't rely on using it at the moment.

#911191

Hi Nigel,

Thanks for the update although this is a bit strange as if I set a conditional test with just one condition i.e.
instead of using

[cred_show_group if="($(road-bike-sub-cat) ne  '' ) OR ($(mountain-bikes-sub-cat) ne  '' ) OR ($(cityurbn-bikes-sub-cat) ne  '' )"  mode='fade-slide']

use just

[cred_show_group if="($(road-bike-sub-cat) ne  '' )"  mode='fade-slide']

the field is displayed correctly so the fact that having no initial value should not be the issue.

to test this I have used:

[cred_show_group if="($(road-bike-sub-cat) ne  '' )"  mode='fade-slide']
<div class="form-group col-md-4">
		<label>[wpml-string context='cred-form-My Rider Profile-86' name='I plan to ride']I plan to ride[/wpml-string]</label>
		[cred_field field='i-plan-to-ride' post='rider-profile' value='' urlparam='' select_text='--- not set ---' class='form-control' output='bootstrap']
	</div>
[/cred_show_group]

so it seems that only the OR test is not working properly and that's what I believe is the real issue.

you can see this is working following the steps:
1. go to the page hidden link
2. click on Road Bike
3. display the related sub alternatives of Road Bike
4. click on one of the sub alternatives
5. display the drop down select list of "I plan to ride" show correctly

For additional test I also used

[cred_show_group if="($(road-bike-sub-cat) ne  '' )"  mode='fade-slide']
<div class="form-group col-md-4">
		<label>[wpml-string context='cred-form-My Rider Profile-86' name='I plan to ride']I plan to ride[/wpml-string]</label>
		[cred_field field='i-plan-to-ride' post='rider-profile' value='' urlparam='' select_text='--- not set ---' class='form-control' output='bootstrap']
	</div>
[/cred_show_group]


[cred_show_group if="($(mountain-bikes-sub-cat) ne  '' )"  mode='fade-slide']
<div class="form-group col-md-4">
		<label>[wpml-string context='cred-form-My Rider Profile-86' name='I plan to ride']I plan to ride[/wpml-string]</label>
		[cred_field field='i-plan-to-ride' post='rider-profile' value='' urlparam='' select_text='--- not set ---' class='form-control' output='bootstrap']
	</div>
[/cred_show_group]


[cred_show_group if="($(cityurbn-bikes-sub-cat) ne  '' )"  mode='fade-slide']
<div class="form-group col-md-4">
		<label>[wpml-string context='cred-form-My Rider Profile-86' name='I plan to ride']I plan to ride[/wpml-string]</label>
		[cred_field field='i-plan-to-ride' post='rider-profile' value='' urlparam='' select_text='--- not set ---' class='form-control' output='bootstrap']
      </div>
[/cred_show_group]

each conditional display works however this is not a feasible solution or a workaround.

all this bring me to the conclusion that the OR in the conditional doesn't work.
any thoughts?

David

#911769

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Yes, the OR test is not working, but specifically for radio fields (which have the problem of the undefined initial state) rather than for select fields, where the OR test works okay.

When the developer works on this radio-field issue they will ensure that it works in this context, with several fields in an OR condition.

I'll let you know when he has an update.

#913076

Great,
Thanks Nigel,

Any update on this if its in the works?
I have a client that waits for this solution and its holding the project completion and delivery.

Please advise,
thanks,

David

#913330

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

It is with our developers and they have agreed that they will find a solution, but it is in the context of all the other work they have on their plate, so I don't know how long it will take.

If this is holding up your client project, might I suggest you drop the Toolset conditional display of the final field and simply add some custom JS to achieve the same?

Between the jQuery methods hide(), change(), and toggle(), you should be able to achieve this with just a few lines of code.

You'll want to use the browser dev tools to check what the appropriate selectors are, but the code will go something like this:

( function( $ ) {
	$( document ).ready( function(){
		// Your code here

		// 1. Hide the 3rd-level field with .hide();

		// 2. add .change() listeners to each of the second level fields which applies .toggle() to the 3rd-level field

	});
})( jQuery );

If you need help with the specifics of the code let me know and I'll take a look. Sorry I'm busy at the moment to look at your page and come up with the exact solution unless you need me to.

#914099

Thanks Nigel,
I understand.
Yes, I do need help with the specifics of the code. if you can help that will be great.

Thanks,

David

#914720

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I set this up on a test site to show what's required, though you will have to make some edits as required.

First, the form itself can include the conditional group wrappers for the second level choices, like so:

	<div class="form-group">
		<label>First choice</label>
		[cred_field field='first-choice' value='' urlparam='' output='bootstrap']
	</div>

[cred_show_group if="($(first-choice) eq  'alpha' )"  mode='fade-slide']
	<div class="form-group second-tier">
		<label>Alpha Therefore</label>
		[cred_field field='alpha-therefore' value='' urlparam='' output='bootstrap']
	</div>
[/cred_show_group]

[cred_show_group if="($(first-choice) eq  'beta' )"  mode='fade-slide']
	<div class="form-group second-tier">
		<label>Beta Therefore</label>
		[cred_field field='beta-therefore' value='' urlparam='' output='bootstrap']
	</div>
[/cred_show_group]

[cred_show_group if="($(first-choice) eq  'gamma' )"  mode='fade-slide']
	<div class="form-group second-tier">
		<label>Gamma Therefore</label>
		[cred_field field='gamma-therefore' value='' urlparam='' output='bootstrap']
	</div>
[/cred_show_group]

	<div class="form-group third-tier">
		<label>Third choice</label>
		[cred_field field='third-choice' value='' urlparam='' select_text='--- not set ---' class='form-control' output='bootstrap']
	</div>

My second level choices are alpha-therefore, beta-therefore, and gamma-therefore.

Note how I have added the class "second-tier" to the second-level choice wrapper DIVs, and "third-tier" to the third-level select field.

I then added some simple JS like so:

( function( $ ) {
	$( document ).ready( function(){
		// Initially hide the final choice
		$(".third-tier").hide();

		// Add change event listeners to second tier
        $(".second-tier input").change( function(e){
            	$(".third-tier").show();
        });
	});
})( jQuery );

You may not need to edit the JS unless you want to tweak how it works.

#914960

Hi Nigel,,
Your workaround works!
Thank you for the great help.
I would ove to know when the OR relationship issue will be fixed and I can remove the custom code for the workaround.
Thanks,
David