Jump to content

Field Dependencies


ryan

Recommended Posts

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

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?)

Soma, I still can't duplicate this one. Tell me if I'm not setting it up correctly. I have a field called "Test Toggle" that when checked shows my repeater. When unchecked, it shows another fieldset called "Test Fieldset" (which itself contains a single text field). See the screenshots that demonstrate the checked and unchecked state of "Test Toggle". The "show if..." rule I've attached to my "rates" repeater is test_toggle!='' and the rule I've attached to my "Test Fieldset" is test_toggle=''. This site already had multi-language enabled. The screenshots don't show it, but I also tried adding a multi-language title field to the repeater, just in case. But that didn't make any difference. 

test_toggle unchecked (test_fieldset shown):

post-2-0-91613500-1380966990_thumb.png

test_toggle checked (test_fieldset hidden and rates repeater shown): 

post-2-0-32500300-1380966997_thumb.png

Can you think of anything else I should try?

Link to comment
Share on other sites

  • 1 month later...

I am using the Futura remixed theme and the admin columns module, and before I added the inputfield.js like stated here http://processwire.com/api/selectors/inputfield-dependencies/ the widths of the columns where set fine, like 70% and 29%. No with the newly added JS the width are very weirdly huge: 98.65625% and 57.65625%

What's wrong and how to fix it?

Link to comment
Share on other sites

I am using the Futura remixed theme and the admin columns module, and before I added the inputfield.js like stated here http://processwire.c...d-dependencies/ the widths of the columns where set fine, like 70% and 29%. No with the newly added JS the width are very weirdly huge: 98.65625% and 57.65625%

The new inputfields.js from the dev branch will attempt to maximize the row with the columns that are in it. If the total does not add up to 100%, it will expand the last visible column to fill the row. I'm guessing this is what you are seeing? This behaves well with the default admin themes (both old and new), but I've not tried Futura Remixed yet. It's possible that theme may need an update if it's not something we can work around. 

I cannot use parent=1 or parent.template=home as a dependency in the visibility option right? Because it does not work for me. =( Also not in the default admin theme.

Dependencies are the field names are they are in the markup (id attributes). While I've not tried it, you may be able to get it to work just by using the parent field as it's named in the markup, which is "parent_id". However, you could only match the ID (number), you couldn't match something like parent_id.template=home. 

Link to comment
Share on other sites

  • 3 weeks later...
Is there a way to make the values of one dropdown dependent on the chosen value of the other dropdown?

For example if I choose in a country dropdown "France" the second City dropdown will show "Paris, Marseille, Lyon, Toulouse etc."

Thanks

Alfred
Link to comment
Share on other sites

It's hackish, but something may work.

When you select the first select, trigger a click on the save button with javascript ( needs a module )

Then after page save,  the other select ( type of page ) uses the data from the first select to query the 'sub' pages

Show the second select only when the first one is not empty with field dependencies.

Forget this, this is not very thoughtful.

Edited by Martijn Geerts
Link to comment
Share on other sites

Is there a way to make the values of one dropdown dependent on the chosen value of the other dropdown?
For example if I choose in a country dropdown "France" the second City dropdown will show "Paris, Marseille, Lyon, Toulouse etc."

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. 

  • Like 19
Link to comment
Share on other sites

Thank you Ryan. PW keeps amazing me. I tested it and it works like a charm.

One thing though. 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).

Link to comment
Share on other sites

Dependencies are the field names are they are in the markup (id attributes). While I've not tried it, you may be able to get it to work just by using the parent field as it's named in the markup, which is "parent_id". However, you could only match the ID (number), you couldn't match something like parent_id.template=home. 

This selector does not work for me, for instance: parent_id=1050

Is there any other way to show a field depending on the parent?

(The selector id=1050 works, so it's no problem to show a field depending on the id of the current page. But I need the parent.)

Link to comment
Share on other sites

Ryan,

I've been experimenting with this a lot — and it's really solid. I can't imagine not having it now.

The only thing I can't sort out (it may not be possible) is how to hide a page field if it returns no results.

For example:

I have a page field that is a sidebar picker.

It uses a custom selector to look for a sibling page named "sidebars".

There isn't a always "sidebars" page defined in every parent, so sometimes the page field is empty.

That can be confusing, so I was hoping I could hide the page field if there are no options available.

I may need a simple module for this instead, but thought I would ask if it's possible dependencies.

Link to comment
Share on other sites

  • 2 weeks later...

This selector does not work for me, for instance: parent_id=1050

Is there any other way to show a field depending on the parent?

I can confirm, this doesn't seem to work for me either. I'm not yet sure why it doesn't work, but will look into this. 

There isn't a always "sidebars" page defined in every parent, so sometimes the page field is empty.

That can be confusing, so I was hoping I could hide the page field if there are no options available.

Currently dependencies can't check if there are options available in a selection field... it can only tell if something is selected and what is selected. I'm not really sure how I'd suggest solving that particular issue, short of a custom module. But for starters, it might be good to set the visibility state of the field to "collapsed only when blank", which should help to keep it out of the way until needed. 

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Just had a reason to play with this via the API for the first time. Adding some config fields to a module and I just have to say WOW!

It's just too easy :)

Thanks again to Ryan for the great work and Avoine for sponsoring!

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Hi, I did not find that mentioned before, there is another limitation of field dependencies.

Chains do not work (yet).

example: field1, field2(hidden), field3(hidden):

1. Display field2, if  field1 has a string -> works!

1. Display field3, if  field2 has a string -> works NOT, if field1 is still empty and therefor field2 is still hidden, error:

    Session: Max number of iterations reached for processing field dependencies (ProcessPageEdit)

Link to comment
Share on other sites

  • 2 weeks later...

I can confirm, this doesn't seem to work for me either. I'm not yet sure why it doesn't work, but will look into this. 

Currently dependencies can't check if there are options available in a selection field... it can only tell if something is selected and what is selected. I'm not really sure how I'd suggest solving that particular issue, short of a custom module. But for starters, it might be good to set the visibility state of the field to "collapsed only when blank", which should help to keep it out of the way until needed. 

Hey,

its because parent_id form field ID isnt prefixed with "Inputfield_" as all other formfields. It simply has the id="parent_id", so this selector doesnt match:

var $field = $("#Inputfield_" + condition.field);
 

Dont know if something else breaks if the form field ID is prefixed.

Cheers

Link to comment
Share on other sites

  • 1 month later...

I've tried using field!='' for a Page field that displays two radio buttons and it doesn't seem to work. I also tried !=0 and >0 but no joy.

Basically I don't want to show a field unless one of the radio options is clicked, and by default neither is, but this scenario just doesn't seem to work with dependencies at present.

Any suggestions?

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