Jump to content

Custom Inputfield Dependencies


Robin S

Recommended Posts

  • 2 weeks later...

Thanks for this module! It saved many hours for me. And one more thing i noticed. It has some bugs with toggle field value as dependency and when is used for field_tab
But all other are works grate!)) Thanks again!

Link to comment
Share on other sites

2 hours ago, regesh said:

It has some bugs with toggle field value as dependency and when is used for field_tab

@regesh, that's a pretty vague statement. A proper bug report needs to include an exact description of the bugs and steps to reproduce them. Otherwise it's difficult to respond.

As far as I can see the module works with FieldtypeToggle just fine. If you want to match a Toggle field in a selector you have to use the integer value - that isn't specific to this module, it's the way the PW core works.

2020-07-15_101907.png.d0a8080b04c2e29824c7a791f832867a.png

And by "field_tab" do you mean the core "Fieldset in Tab (Open)" aka FieldtypeFieldsetTabOpen? The module also works fine with this fieldtype so I don't understand the problem.

If instead you are talking about the tab option of the non-core FieldsetGroup module that is part of ProFields then I've added support for that in v0.2.2.

Link to comment
Share on other sites

  • 2 years later...
6 hours ago, gornycreative said:

Would I be able to use this to check if a repeater matrix item has any items assigned? I want to set up a drop down that only appears when a repeater is populated.

Did you try something already and it didn't work?

You should be able to use either the "Show only if page is matched by selector"...

your_matrix_field.count>0

...or the "Show only if custom PHP returns true" setting...

$items = $page->getFormatted('your_matrix_field');
if($items && $items->count) return true;

If you were wanting to do the opposite, i.e. show the field only when the matrix field is empty, then it should work to put "your_matrix_field.count=0" into the "Show only if page is matched by selector" setting but unfortunately there seems to be a core PW bug: https://github.com/processwire/processwire-issues/issues/1701

So until that's fixed you'd need to use the "Show only if custom PHP returns true" setting instead:

$items = $page->getFormatted('your_matrix_field');
if($items && !$items->count) return true;

 

Link to comment
Share on other sites

I tried using the simple matrix_field.count>0 rule, but it didn't work.

I didn't realize I needed to include the inputfieldset name also. e.g.

matrix_wrapper_fieldset.matrix_field.count>0

EDIT: Nope that didn't fix it. It just stopped showing anything.

For some reason it is not recognizing the count of the matrix items.

Is the data-show-if attribute in the HTML supposed to be escaped? e.g.

data-show-if='meta_zone_1.count>0' data-required-if='meta_zone_1.count>0'

 

Link to comment
Share on other sites

4 hours ago, gornycreative said:

I tried using the simple matrix_field.count>0 rule, but it didn't work.

I didn't realize I needed to include the inputfieldset name also. e.g.

matrix_wrapper_fieldset.matrix_field.count>0

I don't know what the field structure is in your template. It should work fine as described in my previous post. Inputfield names doesn't have much to do with it - you use field names just as you would in any selector. If the selector matches your page in $pages->find($selector) then it should work in the "Show only if page is matched by selector" setting. Seeing screenshots of your template fields and the settings you have chosen for CustomInputfieldDependencies would help.

5 hours ago, gornycreative said:

Is the data-show-if attribute in the HTML supposed to be escaped? e.g.

data-show-if='meta_zone_1.count>0' data-required-if='meta_zone_1.count>0'

That isn't related to this module. It comes from the core show-if and required-if features, so if you are seeing that in your markup it means you are not using the features added by CustomInputfieldDependencies. See the screenshot below.

image.thumb.png.5605d2527599aab3c2a53e06fde83552.png

 

Link to comment
Share on other sites

  • 1 year later...

@Christophe, glad you find it useful.

5 hours ago, Christophe said:

I'm using "Show only if page is matched by custom find" and the parent (page) id.

Technically you don't need Custom Inputfield Dependencies if you want to show/hide a field according to the parent page ID. The PW core includes a "Parent" field in Page Edit on the "Settings" tab. This field is named "parent_id" so you can do something like this:

image.png.e6ea856aca36cbf5f431c52d2b44cb3a.png

  • Like 1
Link to comment
Share on other sites

For me, parent_id= 1314 or parent.id=1314 in "Show this field only if" doesn't work.
It hides the field.

It works only as expected in "Show only if page is matched by custom find" or in "Show only if page is matched by selector" where I put this time parent.id=1314 that was given by the "Show only if page is matched by custom find" field when I was using it before.

In Visibility, I'm using "Open when filled + Closed when blank".

Edit: I didn't deactivate your module when trying it, but I don't think it could have had an impact on the result.

Edited by Christophe
Link to comment
Share on other sites

  • 2 weeks later...

So, I had parent.id=1314 in "Show only if page is matched by custom find", and the editor wants also the video field showing on a specific page not included by the first filter.
I can't have it work.
So, out of curiosity, I tried again in "Show this field only if". And parent.id=1314 || id=1250 works (parent.id=1314 | id=1250 also).
And I don't know why but this time 
parent_id=1314 alone works (but not parent_id=1314 || id=1250 - with the double or single pipe operator - for the specific page).
I don't know if all this is "normal". There is certainly an explanation.

Edit: The field appeared for the page (with id 1250) but I had the impression that it wouldn't work and it didn't (the video disappeared after saving the page).
Also, it blocked, at least for this specific page and the children of the "parent" page, the "View" link. 
In fact, I had to just put id=1250 to make it work.
Now, I'm back with 
parent.id=1314 in "Show only if page is matched by custom find".
The field is hidden but the video is still there.

I might just create another template for this specific page, as the video appears at the bottom after a lot of content in this particular case and should preferably be at the top.

Edited by Christophe
Link to comment
Share on other sites

@Christophe, I can't follow what you're doing so if you have a question specifically about Custom Inputfield Dependencies rather than the core show-if features then please rephrase it and include some screenshots.

For now what I can say is:

Custom Inputfield Dependencies uses the $pages->find() selector syntax as described in the PW docs.

image.png.c345e2bcdf6b91cbd16ad48eebd9b15e.png

This is a different syntax than the core show-if selectors, so you can't just copy/paste selectors from one to the other. Syntax like "parent.id=1314 || id=1250" and "parent.id=1314 | id=1250" is not valid for $pages->find().

If you want to match one field/value combination OR a different field/value combination then you need to use OR-group syntax: https://processwire.com/docs/selectors/#or-groups

And InputfieldSelector (the inputfield used by Custom Inputfield Dependencies for "Show only if page is matched by custom find") doesn't support OR-groups so you would have to use a selector string in "Show only if page is matched by selector".

(parent.id=1314), (id=1250)

 

  • Like 1
Link to comment
Share on other sites

I think I had tried it in "Show only if page is matched by selector" but without the parentheses, based on what "Show only if page is matched by custom find" was displaying (but yes it was saying that 0 pages corresponded).
With the brackets it works. Thank you!

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...