Jump to content

Field Dependencies


ryan

Recommended Posts

Thanks for testing Raymond. 

This does'nt work:
d_product>=1008,d_product<=1011

Just pushed a fix for this in the latest commit. Had to adjust the order that the operators were named in in the Javascript regex. 

This also does'nt work:
d_product=1008,d_product=1009,d_product=1010,d_product=1011

You mentioned that your page field only holds a single page. As a result, the above can't work since it is asking for all of those IDs to match at the same time. Such a scenario would only be possible with a multi-page field. 

This does'nt work for now as expected (described in current limitations):
d_product=1008|1009|1010|1011

The OR syntax "|" in fields/values isn't yet supported for dependency selectors. I will be adding support for it, but not until everything else is considered stable with the dependencies. Basically, I'm trying to keep the number of variables at a minimum so that people can start using this stuff in a stable state sooner rather than later. 

Optimal would be if it could do something like the following. I saw this is planned for a future release.
d_product.d_type_select.name='regioblad'

You probably won't be able to do it exactly like that. But my plan is to let PW pre-process selectors to convert some things to page IDs before sending them to the Javascript side. For instance, you'll be able to do:

d_product=/products/regioblad/

We might also be able to support:

d_product.name=regioblad

  • Like 1
Link to comment
Share on other sites

Thanks for the fast fix Ryan.
 

 

This does'nt work:
d_product>=1008,d_product<=1011

Just pushed a fix for this in the latest commit. Had to adjust the
order that the operators were named in in the Javascript regex. 

I tried it and can confirm it works now the way you would expect.


 

This also does'nt work:
d_product=1008,d_product=1009,d_product=1010,d_product=1011

You mentioned that your page field only holds a single page. As a result, the above can't work since it is asking for all of those IDs to match at the same time. Such a scenario would only be possible with a multi-page field.

Indeed you're right about that, i was thinking it would be looking if the d_product value was one of those values, but of course it is looking if the field has all those values.

 

This does'nt work for now as expected (described in current limitations):
d_product=1008|1009|1010|1011

The OR syntax "|" in fields/values isn't yet supported for dependency selectors. I will be adding support for it, but not until everything else is considered stable with the dependencies. Basically, I'm trying to keep the number of variables at a minimum so that people can start using this stuff in a stable state sooner rather than later.

I was'nt expecting it would work in this early stage.

Basically, I'm trying to keep the number of variables at a minimum so that people can start using this stuff in a stable state sooner rather than later.

Yes, you're absolutely right

Link to comment
Share on other sites

I was playing around with concat fields, this way you can compair to nested values other then an page id. For example to show/hide certain fields.

The only thing is that it is not 'live' but only shows/hides the regarding fields after the page is saved.

For example if you have a single-page field type for example with 3 pages with names "one, "two", "three". This field is called "choice".

Then a concat field with the name "choice_concat" and "choice.name" in the "Names of fields to concatinate", assigned to the same template would be able to target in a "Show this field only if..." for example the condition is "choice_concat=two".

But keep in mind this only shows/hides the fields after the page is saved, and not live at modifying the value that has the dependency.

Its more then logic why this is, because the concat field only gets its value when its modified after the page is being saved.

Note that the above example is not complete. The setup i was trying it out has a single-page select and those related pages have a single-page select too. The latter one im targeting with the condition. to show/hide certain fields. So actualy the concat field condition value is something like this: "choice_a.choice_b.name"

Link to comment
Share on other sites

Strange problem here: I have a text field "highlight" showed only if checkbox "spotlight" is checked. Field is never showed. This because condition.type is not "show", never.

And.. is correct that the check runs twice?

Field "wrap_Inputfield_cover_highlight" detected a change to a dependency field! Beginning dependency checks... 
---- 
Start Dependency 0 
Condition type: show 
Field: spotlight 
Operator: = 
Required value: 1 
Value #0 - Current value: 1 
Value #0 - Matched? YES 
---- 
---- 
Start Dependency 1 
Condition type: required 
Field: spotlight 
Operator: = 
Required value: 1 
Value #0 - Current value: 1 
Value #0 - Matched? YES 
---- 
Summary (required/matched): 2 / 2 
Determined that field "cover_highlight" should be visible. 
------------------------------------------------------------------- 
Field "wrap_Inputfield_cover_highlight" detected a change to a dependency field! Beginning dependency checks... 
---- 
Start Dependency 0 
Condition type: show 
Field: spotlight 
Operator: = 
Required value: 1 
Value #0 - Current value: 1 
Value #0 - Matched? YES 
---- 
---- 
Start Dependency 1 
Condition type: required 
Field: spotlight 
Operator: = 
Required value: 1 
Value #0 - Current value: 1 
Value #0 - Matched? YES 
---- 
Summary (required/matched): 2 / 2 
Determined that field "cover_highlight" should be visible.
 

Required is not setted.

Dependencies in "input" tab works fine.

Last dev.

Thanks

Link to comment
Share on other sites

Sometimes requiredIf isn't removed from database.

Thats what i noticed too. As soon you have set a requiredIf condition, saved it and then uncheck required, the condition still remains in the database. This causes the fields to showup rumbled (wrong calculations of field width), it also still shows a * character on the field.

Link to comment
Share on other sites

With both *If, condition type is always "required" so we never use

				if(condition.type == 'show') {
					if(!$fieldToShow.is('.InputfieldStateHidden')) {
						$fieldToShow.addClass('InputfieldStateHidden').hide();
						consoleLog('Field is now hidden.');
						numVisibilityChanges++;
					} else {
						consoleLog('Field is already hidden.');
					}
				} else if(condition.type == 'required') {
					$fieldToShow.removeClass('InputfieldStateRequired').find(":input.required").removeClass('required');
				}
Link to comment
Share on other sites

Thats what i noticed too. As soon you have set a requiredIf condition, saved it and then uncheck required, the condition still remains in the database. This causes the fields to showup rumbled (wrong calculations of field width), it also still shows a * character on the field.

I've committed an update that I think should fix this–please let me know if you still experience it. I wasn't able to duplicate exactly what you are talking about, but it was more just a matter of available time, and think I knew what the issue was. Just looking for confirmation that I fixed the right thing, but definitely found an issue that needed fixing either way. 

With both *If, condition type is always "required" so we never use

I'm not sure I understand the question/comment/request?

Fantastic functionality Ryan. Will the field dependencies work within repeaters?

I think it probably depends on the situation. But there are likely several scenarios that won't work when it comes to repeaters, because repeaters manipulate the field names behind the scenes, and both the definition of dependencies as well as the JS require the original field names to be in tact. 

  • Like 2
Link to comment
Share on other sites

I've committed an update that I think should fix this–please let me know if you still experience it. I wasn't able to duplicate exactly what you are talking about, but it was more just a matter of available time, and think I knew what the issue was. Just looking for confirmation that I fixed the right thing, but definitely found an issue that needed fixing either way.

It looks like this fixed the problem. Now making a field required and setting the "Required only if..." in conjunction with "Show this field only if..." seems to work as expected. It seems to handle the column width fine again.

  • Like 2
Link to comment
Share on other sites

I'm not sure I understand the question/comment/request?

Focused on javascript I made some tests. Also with the last fixes.

My situation:

  • checkbox "new"
  • checkbox "hightlight"
  • image "highlight_cover"
  • test "highlight_text"

With

text: {"columnWidth":50,"required":1,"requiredIf":"new>0","showIf":"higlight>0"}
image: {"columnWidth":50,"required":1,"requiredIf":"new>0","showIf":"highlight>0"}

or (change requiredIf to the same filed, only to test, if required is active the field result required when showed and the check works)

text: {"columnWidth":50,"required":1,"requiredIf":"highlight>0","showIf":"higlight>0"}
image: {"columnWidth":50,"required":1,"requiredIf":"highlight>0","showIf":"highlight>0"}

image and text are not showed.

With

text: {"columnWidth":50,"required":1,"requiredIf":"new>0","showIf":"higlight>0"}
image: {"columnWidth":50,"required":1,"showIf":"highlight>0"}

only image is showed (and required).

With

text: {"columnWidth":50,"required":1,"showIf":"higlight>0"}
image: {"columnWidth":50,"required":1,"showIf":"highlight>0"}

image and text are showed and required.

With consoleLog active and requiredIf I noticed that out of the loop

if(condition.type == 'show') {

is never true, so fields are required but not showed.

Thanks

  • Like 1
Link to comment
Share on other sites

I might have found a bug with field dependencies and the image field.

I have the Visitibility Presentation set to default "Always Open (default)" and have set "Show this field only if" to the folowing condition:

p_type_select!=1024,p_type_select!=1025,p_type_select!=1026,p_type_select!=1032,p_type_select!=1186,p_type_select!=1187

When i try to upload an image (both drag&drop and with the button) it somehow fails. Removing the "Show this field only if" condition makes the field useable again.

Note: The image field is inside a Field Set Tab, but im not sure if thats the cause of the problem.

  • Like 1
Link to comment
Share on other sites

 

Fantastic functionality Ryan. Will the field dependencies work within repeaters?
I think it probably depends on the situation. But there are likely several scenarios that won't work when it comes to repeaters, because repeaters manipulate the field names behind the scenes, and both the definition of dependencies as well as the JS require the original field names to be in tact. 
 

How would the syntax for verifying such a field in a repeater could look like in general?

E.g. if the repeater "contentblock" has a field "contentblock_headline" I tried the following, which doesn't work:

$contentblock->contentblock_headline!=''

Has anybody successfully verified a field within a repeater and could tell me how to do that?

Link to comment
Share on other sites

Thanks for the testing and reports maba and Raymond, I'll experiment here and see what I can find/fix. But regarding the image field, I don't think you'll be able to use that as a live dependency because the ajax upload isn't submitting the entire form, just a single field. So when it gets processed, the context of other fields is not known. Only the existing page state is known. So that dependency would probably only come into play after the page is saved in full. As a result, image/file fields may not be good candidates for dependencies, unless we turn off the ajax upload for that situation. 

E.g. if the repeater "contentblock" has a field "contentblock_headline" I tried the following, which doesn't work:
$contentblock->contentblock_headline!=''
A repeater is a PageArray, so you'd have to extract an element from it first. Like if you wanted the first element:
if($page->contentblock->first()->contentblock_headline != '') {
  // something
}
  • Like 1
Link to comment
Share on other sites

A repeater is a PageArray, so you'd have to extract an element from it first. Like if you wanted the first element:

if($page->contentblock->first()->contentblock_headline != '') {
  // something
}

So for repeaters dependencies could just be used via the API, not in the field settings, right?

Link to comment
Share on other sites

So for repeaters dependencies could just be used via the API, not in the field settings, right?

That code snippet doesn't really have anything to do with dependencies. Sorry I thought it was just a side question about repeaters, not dependencies. 

If you want to show/hide a repeaters field (the entire thing) based on the value of some other field in the form, you should be able to do that. Or if you want to show/hide some field within a repeater (all of them at once) based on the value of some field outside the repeater, that might possibly work too. But if you want to build-up dependencies based upon values within the repeater items, I don't think you'll be able to do that at present. 

Link to comment
Share on other sites

I'm not 100% sure wether it is a bug in the field dependies or an issue with form builder:

On my PW dev install with form builder plugin installed, I can not set "field only visible if" + "required only if" at the same time.

Example:

I have field5, which should only be visible if option3 is selected in field4.

But if option3 is selected, a value in field5 is required.

The combination of both doesn't seem to work.

I can select "only visible if", which works fine. But if I put the same condition in the "only required if" option, it doesn't work (field5 won't show up).

If I select "only required if", it works fine to, but field5 is not hidden if option!=3 is selected.

I hope I made myself clear, having a hard time trying to describe my problems in english properly (although it might also be a bit complex to describe it in german.. ;) )

Link to comment
Share on other sites

1. Question:

How can I configure OR conditions? I read in the limitations, that | won't work yet. Is there a workaround? I tried fieldX=value1, fieldX=value2 but that doesn't seem to work.

2. Question:

I'm not 100% sure wether it is a bug in the field dependies or an issue with form builder:

On my PW dev install with form builder plugin installed, I can not set "field only visible if" + "required only if" at the same time.

Example:

I have field5, which should only be visible if option3 is selected in field4.

But if option3 is selected, a value in field5 is required.

The combination of both doesn't seem to work.

I can select "only visible if", which works fine. But if I put the same condition in the "only required if" option, it doesn't work (field5 won't show up).

If I select "only required if", it works fine to, but field5 is not hidden if option!=3 is selected.

I hope I made myself clear, having a hard time trying to describe my problems in english properly (although it might also be a bit complex to describe it in german.. ;) )

Link to comment
Share on other sites

I get strange behaviors when using a checkbox to show/hide a repeater field it seems very buggy.

I try a setup like:

Checkbox

on : show repeater / hide other fieldset

off: hide repeater / show other fieldset

Inititially it works fine, but as soon as I created a repeater and delete it again, then save. The toggle with the checkbox doesn't hide the repeater anymore. I need to save it again with checkbox unchecked, but doesn't matter what it just is completly messed up.

---- 

Maybe not related: Additionally I recognized something, I have repeater with and a title field language (title is required), and sometime when saving and not filling in title (required) I get this notice

Notice: Trying to get property of non-object in /home/www-data/mittendrin.update.ch/wire/modules/LanguageSupport/LanguageSupport.module on line 209 Notice: Trying to get property of non-object in /home/www-data/mittendrin.update.ch/wire/modules/LanguageSupport/LanguageSupport.module on line 209 Notice: Trying to get property of non-object in /home/www-data/mittendrin.update.ch/wire/modules/LanguageSupport/LanguageSupport.module on line 209 Notice: Trying to get property of non-object in /home/www-data/mittendrin.update.ch/wire/modules/LanguageSupport/LanguageSupportFields.module on line 131

Which is a notice, ok,  but the strange thing is that the repeater title language suddenly doesn't have languages fields anymore, just one title text field. The repeater has 3 ready pages.

And also maybe you already know but "required" doesn't work with repeater, but the option is there, but maybe it's because of dependencies?

Link to comment
Share on other sites

I'm not 100% sure wether it is a bug in the field dependies or an issue with form builder:

On my PW dev install with form builder plugin installed, I can not set "field only visible if" + "required only if" at the same time.

Thanks I was able to reproduce. Can you try out the latest commit to dev to see if this fixes the issue?

In addition to column widths, this version also adds management of column heights–it attempts to normalize the heights of all columns in the same row dynamically, depending on what's shown, in the same way it does column widths. 

How can I configure OR conditions? I read in the limitations, that | won't work yet. Is there a workaround? I tried fieldX=value1, fieldX=value2 but that doesn't seem to work.

OR conditions are not yet supported. 

I get strange behaviors when using a checkbox to show/hide a repeater field it seems very buggy.

I've tried to duplicate the issue you mentioned, but can't so far. I probably don't fully understand what you are trying to do. But I can envision a lot of potential problems with combining dependencies and repeaters, so I think we will probably disable the capability once this goes beyond the dev branch.

Maybe not related: Additionally I recognized something, I have repeater with and a title field language (title is required), and sometime when saving and not filling in title (required) I get this notice

I noticed some uncommitted updates I had, related to the line where that error occurred. I don't remember exactly what prompted me to make the changes, but it seems like I may have run into the same error you did. I went ahead and committed that now. 

As for multi-language fields, I've not been able to go there yet with dependencies. No code has been written to support them yet. But this is something that certainly is feasible and I do plan to add. However, you should be able to show/hide a multi-language field based on the values in a non-multi-language field, but I'm not sure you can do more than that at present. 

And also maybe you already know but "required" doesn't work with repeater, but the option is there, but maybe it's because of dependencies?

I think that it's showing the dependency options for pretty much all fields at this point. I'm going to wait and see how far we get in terms of field support before I start adding exclusions. But we will be adding some exclusions in 2.4. 

Link to comment
Share on other sites

@ryan: "required if" + "view if" seem to be partly fixed.

I just updated to latest dev and have the following behaviour:

My current version of the form has a fieldset, which is only visible if a certain box is checked.

Within this fieldset, all required fields are shown properly in the editor, but the data in the DB is "null".

I have 3 required fields within the fieldset which act like this and I have 3 other fields in subfieldsets, which are only required if another field within the same subfieldset has a value>0. Same behaviour here...

Link to comment
Share on other sites

Ryan, so showing or hiding a repeater isn't supported? I'm NOT using dependecies in the repeater but to show/hide the complete repeater.

Again, I have this setup, with a checkbox to toggle a fieldset and a repeater (also a fieldset no?)

I have a simple checkbox 

checked : show repeater / hide other fieldset

unchecked: hide repeater / show other fieldset

 

Multilanguage installed. Repeater has also multilanguage title. But I don't think it has to do this it.

 

Can anybody reproduce this pls? Lately anything I report, Ryan doesn't seem to be able to reproduce. :/

 

----

 

Required option:

The required option for a repeater field was always there, it has nothing to do with dependencies. But it doesn't work with them to set a repeater required.

Link to comment
Share on other sites

I have problems with an image field. If I show that image field depending on another field (checkbox=1) the image field shows up, but doesn't allow any uploads. When trying to upload (both drag&drop and manually) the progress bar is shown, but after that nothing happens, progress bar disappears and image is gone. No errors in log or console.

Link to comment
Share on other sites

I have problems with an image field. If I show that image field depending on another field (checkbox=1) the image field shows up, but doesn't allow any uploads. When trying to upload (both drag&drop and manually) the progress bar is shown, but after that nothing happens, progress bar disappears and image is gone. No errors in log or console.

Image fields can't be used with dependencies at present because they are ajax-upload driven. As a result, the page receives the image before it knows about the dependency condition being met, and the image is refused. I suppose this could be solved by having dependencies operate only at the Javascript level and not at the server side, but that wouldn't be as safe either. I'll keep thinking on this one. 

I just updated to latest dev and have the following behaviour:
My current version of the form has a fieldset, which is only visible if a certain box is checked.
Within this fieldset, all required fields are shown properly in the editor, but the data in the DB is "null".
I have 3 required fields within the fieldset which act like this and I have 3 other fields in subfieldsets, which are only required if another field within the same subfieldset has a value>0. Same behaviour here...

Is this in the page editor or in a Form Builder form (or somewhere else?). If it's a Form Builder form, it be good if I could take a look at an export of it, so I'd have a good test case to debug from. Please PM to me if possible. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...