Jump to content
ryan

Field Dependencies

Recommended Posts

Probably basic, but can anyone tell me how to show a particular field if the 2nd element of a radio is selected? Thank you.

Share this post


Link to post
Share on other sites

Hey Ryan,

I've loved the field dependencies the moment we finally upgraded to processwire 2.4.

The only thing i'm truely missing is a way to select with an OR value.

I'm currently using field dep. to make "widgets" for lack of a better name and not every "widget" has a body, but multiple do use the body.

Currently it seems I'm stuck using multiple body tags unless I'm mistaken.

Bassicly I'm looking for a way to use the body field if widget_type == "type1" OR "type2"

Is this a possibility or will this be a feature implemented in the future?

Keep up the awesome work you do. Processwire has quickly become my favourite system to work with.

Share this post


Link to post
Share on other sites

This is a bit old, but I'm stubbing my toe on it.

Actually, you can do this on the dev branch. Lets assume that cities are children of countries and that is reflected in your page structure (i.e. /countries/france/paris/). Create your 2 page fields (country and city), and configure 'country' as a single page field with "parent" set to "/countries/". Next, for the "city" field configuration, use the "Custom selector to find selectable pages", present on the "input" tab. In that field, enter "parent=page.country". Save and try it out. This works with select, selectMultiple and asmSelect fields (and possibly others), though not yet with checkboxes, radios or PageListSelect.   

I have this working, but when nothing has been selected for "country" the "city" select shows all the root pages starting with home. Is the only way around that to set the "city" visibility to country!="" ? Perhaps I'm just being dense today, but I can't find any other way around it.

Share this post


Link to post
Share on other sites

This is a bit old, but I'm stubbing my toe on it.

I have this working, but when nothing has been selected for "country" the "city" select shows all the root pages starting with home. Is the only way around that to set the "city" visibility to country!="" ? Perhaps I'm just being dense today, but I can't find any other way around it.

Have the same issue using the latest dev branch. I think something changed in the core...

If I specify for my province select field also a template parent=page.country, template=mytemplate I end up with the name of the template as a value when nothing is selected in the first select. So no good!

- edit -

the field which depend on another field, in my case "province" depends on "country":

in province visibility, and show this field only if... I use "country>0"

This hides the province field, until I select a country. Then it just shows the corresponding values.

It's a pitty this cannot be done on the front-end though...

Share this post


Link to post
Share on other sites

I was just wondering if it is possible to use roles as dependency?

I've read Ryans post https://processwire.com/talk/topic/4323-field-dependencies/page-3#entry42957 and thought it might be possible.

Has someone an answer to this question? I would like to make a membership number required but only for members and not for admins.

  • Like 1

Share this post


Link to post
Share on other sites

Actually, you can do this on the dev branch. Lets assume that cities are children of countries and that is reflected in your page structure (i.e. /countries/france/paris/). Create your 2 page fields (country and city), and configure 'country' as a single page field with "parent" set to "/countries/". Next, for the "city" field configuration, use the "Custom selector to find selectable pages", present on the "input" tab. In that field, enter "parent=page.country". Save and try it out. This works with select, selectMultiple and asmSelect fields (and possibly others), though not yet with checkboxes, radios or PageListSelect. 

Just discovered my need for this on a mission to try something and I must say...awesome. Couldn't get it working at first my confusion lay in the fact I was calling:

parent=page.province

thinking it referred to the page but it's the field I needed to target i.e.

parent=page.country_province - where "country_province" is the name of the select field I am using.

Share this post


Link to post
Share on other sites

I was just wondering if it is possible to use roles as dependency?

I've read Ryans post https://processwire.com/talk/topic/4323-field-dependencies/page-3#entry42957 and thought it might be possible.

Has someone an answer to this question? I would like to make a membership number required but only for members and not for admins.

I just figured it out. I read in another thread (can't remember which), that roles do have subfields like roles.name. Using these did not work, but I found that ProcessLister used the id's in it's selectors instead of the names. So just look for the id of your role and use "roles=ID" in the dependency field. 

Share this post


Link to post
Share on other sites

It seems like OR in dependencies is not working for radio buttons.

I want to show a field only some specific options of the radio input "ad_frequency" are checked.

I tried this in field dependencies settings:

ad_frequency=1082, ad_frequency=1083, ad_frequency=1084

If I set it to a single radio option like

ad_frequency=1082

everything is working as expected.

In the docs it says that this will be implemented.

Does anyone know, when?

  • Like 1

Share this post


Link to post
Share on other sites

@sforsman

Thanks, but not working. I get a JS error

Uncaught Error: Syntax error, unrecognized expression: #Inputfield_ad_frequency_1082|1083|1084 

Attribute data-show-if="ad_frequency=1082|1083|1084" in the field wrapper.

I'm on 2.5 stable and on a frontend form where other dependencies are working fine.

Share this post


Link to post
Share on other sites

Does anyone know when OR condition s will be available?I' be willing to donate towards developmentin near future.

Share this post


Link to post
Share on other sites

This may not be the right place to post, but I'll try anyway...

I'm currently preparing a little presentation to introduce PW to our company. Most stuff we do development-wise, is strictly frontend. But every now and then, we do backend stuff too, which mostly (always?) ends with choosing Wordpress. "Because it's so famous", "because it's the only CMS our other in-house developers also know", "because there are so many plug-and-play themes/plugins"...

There are a few medium-sized projects coming up where we won't only cover the frontend, so I thought it was time to introduce folks here that - yes indeed - there are worthwhile alternatives out there.

I've got maybe 80% of the material together that I'd like to present, but I was wondering if there is a PW-profile of the hotel website which is shown in Ryan's video @ http://processwire.com/api/selectors/inputfield-dependencies/ (or any other similar profile / demo site which uses field dependencies).

If possible, I'd like to walk through a demo-install with people, and maybe even let them play around themselves.

Too many folks here actually have no clue when it comes to backend dev work. I'd like to show them how much can be achieved, with "out of the box" PW tools, even for heavily customized stuff. And certainly, Field Dependencies is such a corner-stone.

Share this post


Link to post
Share on other sites

@LostKobrakai

So just look for the id of your role and use "roles=ID" in the dependency field. 

You using in "show this field only if" with something like "roles=1011" and this is working for you?

Share this post


Link to post
Share on other sites

 Is it also possible within a repeater field? I tried it with this selector: parent=page.name-repeaterfield.country but it is probably missing the individual repeater field (or maybe is it not possible at all this way).

I have the same problem. It is possible within a repeater field? When they are outside from repeater , no problem.

Any help?

Share this post


Link to post
Share on other sites

Each repeateritem is actually a hidden but real page, so they're assigned dynamic names. These include the id of the current repeater item, so I think the field dependencies don't work in repeaters, because the name matching just doesn't work. checkbox_1029 just isn't checkbox. Also the same field can be used normaly on the same page as the repeater field resides, so there could be a normal checkbox and some checkbox_1029, checkbox_1034. I don't know for sure, but I think, that's why Ryan left it out by now.

Share this post


Link to post
Share on other sites

I tried with their dynamic name and all known ways (for me of course) without success. 

Ryan, please, can you help in that situation, workaround?

Thanks!

Share this post


Link to post
Share on other sites

@awebcreature

If you don't trust my explanation, here is a statement from Ryan that this is currently not intended to work. https://github.com/ryancramerdesign/ProcessWire/issues/803#issuecomment-64982758

Only option would be to hook the dependency management and add a own javascript file which handles the repeaters.

Share this post


Link to post
Share on other sites

Thank you, LostKobrakai, for your explanation and that link to Ryan's post. Now I will try with PageTable field to solve that problem.

All the best!

Share this post


Link to post
Share on other sites

Some time ago I added support to core for repeaters, but it's very vage and uncomplete and only works with = operator. So it's already there for some time.

https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/InputfieldWrapper.php#L316

Thing was that it wasn't saving those fields anymore because of something else related, I can't really remember now. :)

To enable fields with sowIf getting saved see in wire/config.php how to make it work.

/**
 * Settings specific to InputfieldWrapper class
 *
 * Setting useDependencies to false may enable to use depencencies in some places where
 * they aren't currently supported, like files/images and repeaters. Note that setting it
 * to false only disables it server-side. The javascript dependencies work either way. 
 *
 * Uncomment and paste into /site/config.php if you want to use this
 * 
 * $config->InputfieldWrapper = array(
 *  'useDependencies' => true,
 *  'requiredLabel' => 'Missing required value', 
 * );
 * 
 */
  • Like 1

Share this post


Link to post
Share on other sites

=operator dependencies still work fine in repeaters. At least as of 2.5.3 — haven't checked the dev branch.

Share this post


Link to post
Share on other sites

Actually, you can do this on the dev branch. Lets assume that cities are children of countries and that is reflected in your page structure (i.e. /countries/france/paris/). Create your 2 page fields (country and city), and configure 'country' as a single page field with "parent" set to "/countries/". Next, for the "city" field configuration, use the "Custom selector to find selectable pages", present on the "input" tab. In that field, enter "parent=page.country". Save and try it out. This works with select, selectMultiple and asmSelect fields (and possibly others), though not yet with checkboxes, radios or PageListSelect. 

Can't puzzle this one out. I structure as you said (using categories/category/subcat, actually, but I'll stick to the geographic example to keep things simple), and it _looks_ as if it is working brilliantly. The proper set of cities pops up when I select a country. However, it won't save.

After I click "save," the city select dropdown resets to nothing (in fact, it isn't even populated by any choices until I go back to the country dropdown and select something else), and the city info is not being saved to the database at all.

I have painstakingly fiddled with each setting in the associated fields and templates and cannot get it working. Once idea: Could this possibly be because the template on which I am placing these dependent dropdowns belongs to pages that reside on a different branch of the page tree (not nested underneath, in this example, city)? Seems unlikely, but wanted to check before I pulled out still more hair over this.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...