Jump to content

Field Dependencies From a Repeater


pers0n
 Share

Recommended Posts

I have a field called "number of columns" its an integer (the max is 5, just a note in the description)

If it is set to >0 then it shows a repeater (this is working)

The repeater then has 5 textfields, and each one needs to only show up if the number of columns requires it

so for example, if somone puts in "2"

then the repeater shows up (this works as I mentioned) and the repeater should only show 2 of the textfields (this is the part that isnt working).

I've went in and set

col1_text to be visible if num_of_columns>0

col2_text to be visible if num_of_columns>1

however, processwire isn't saving that setting and so it ignores it.

I'm on PW 2.4.0 and I'm trying to build some kind of dynamic table creator (it will be limited to 5 columns max) with a decent UI, so people can easily track the columns, having the columns in tabs or making it to where someone could accidently make 3 colums in one row and 4 in the other isn't good and so this is the solution I've come up with, but its not working for some reason :(

Link to comment
Share on other sites

Avoid using dependencies in repeaters, as support is limited at present. I hadn't intended to implement them at all, and haven't written any code to support them as yet. Another user submitted a pull request to add basic support, but I think that only works with the equals "=" operator at present. If it proves to be reliable with that one operator, we will work to expand on that PR to add support for other operators. 

Link to comment
Share on other sites

  • 2 weeks later...

Hi Ryan,

I could use at least basic support for this too — any chance you've been able to evaluate that pull request?

I realize this is probably super complicated to work out, and goes back to the flexibility in page design discussion.

Soma posted this workaround (maybe that is the same method as the PR). I'll give it a try for now.

Just looked in the latest version of InputFieldWrapper.php and I see Soma's code. 

Not working for me at the moment, so test with something little more basic.

Link to comment
Share on other sites

Tested this a lot more today, and am running into some issues.

"show this field only if…" seems to work fine. Fields show/hide.

However, any fields that have a visibility rule applied to them don't actually save.

For example:

I have a files field that is set to display if a select (add_files) is set to yes.

That field saves and tracks changes fine when it has no visibility rule set, but as soon as I add 

add_files=2016 the field still shows/hides correctly, but no longer saves changes.

I've tested this with several different fields in several different browsers.

Link to comment
Share on other sites

If repeaters that have the "data-show-if" attribute aren't being processed, perhaps the issue is something to do with how they are being interpreted by isProcessable() in InputFieldWrapper.php? 

I'm just looking quickly — there is a lot here to get your head around with repeaters.

Still standing here in my dancing shoes. No music. No dance partner.

*sips drink. blinks.*

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

OK, so I'm fairly certain this is a dead horse, as Ryan already mentioned that he doesn't intend to support field dependencies in repeaters.

That said, I feel like there is still a chance this could be fixed (at least for the = operator). The solution is likely over my head, but I'm going to outline what I know in hopes that someone might find a solution.

The crux of the problem: Dependent fields within repeaters show/hide as expected, but they don't save.

*Note: they can only be dependent on another field within the repeater.

Here is the code for a textarea in a repeater without any field dependency (Saves as expected)

<li class="Inputfield InputfieldTextarea Inputfield_body_repeater28589 InputfieldColumnWidthFirst" id="wrap_Inputfield_body_repeater28589">
    <label class="InputfieldHeader InputfieldStateToggle" for="Inputfield_body_repeater28589"><i class="toggle-icon fa fa-angle-down"></i>Body</label>
    <div class="InputfieldContent">
        <textarea id="Inputfield_body_repeater28589" class="FieldtypeTextarea InputfieldMaxWidth" name="body_repeater28589" rows="5"></textarea>
    </div>
</li>

Same textarea in a repeater, that is dependent on the value of another field (doesn't save).

<li class="Inputfield InputfieldTextarea Inputfield_body_repeater28589 InputfieldStateShowIf InputfieldColumnWidthFirst" data-show-if="sidebars_repeater28589=27189" id="wrap_Inputfield_body_repeater28589" style="display: block;">
    <label class="InputfieldHeader InputfieldStateToggle" for="Inputfield_body_repeater28589"><i class="toggle-icon fa fa-angle-down"></i>Body</label>
    <div class="InputfieldContent">
        <textarea id="Inputfield_body_repeater28589" class="FieldtypeTextarea InputfieldMaxWidth" name="body_repeater28589" rows="5"></textarea>
    </div>
</li>

The only difference is the class "InputfieldStateShowIf" and the "data-show-if" Attribute.

I suspect there is an issue with how these fields are interpreted by isProcessable() in InputFieldWrapper.php

Of course, this may all be fairly obvious to many of you, and the problem may be a lot more complicated. I really don't know. :)

Contemplating the actual process behind repeaters and field dependencies causes my mind to seize up, so I'm just leaving this information here incase anyone wants to jump and take a look. 

If this were to work (even for just simple = dependencies) the possibilities are huge!

Link to comment
Share on other sites

  • 1 month later...

Just ran into this issue myself as I wanted to use showIf in a reasonably complicated fashion with a repeater so I guess I'll just disable the showIf for now.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

I don't  know if Ryan can be bullied into supporting field dependencies with repeaters but maybe he'll look at it if enough people chime in to request it. :-[

I have a repeater that's full of dependency potential. Empty text field that, if it contains data, needs a modifier field to appear. Categories that depending on which category is selected would require additional fields relevant to that category. etc.

It would be very useful to streamline the interface and reduce potential user input error If I could only display the fields relevant to the data (all of which is contained within the same repeater.

If the fields won't save, there's no point because chaos will ensue but if this could be made to work it would add a whole new level to repeater love from me.

So...pretty please?

  • Like 1
Link to comment
Share on other sites

Hi digitex,

Dependencies within repeaters are now working in the latest dev. I think support is limited to (field=value), but that accomplishes a lot.

I would also recommend taking a look at the new PageTable fieldType. Apparently it now has support for multiple templates, so you might be able to accomplish what you need without the overhead of repeaters.

  • Like 3
Link to comment
Share on other sites

Hi digitex,

Dependencies within repeaters are now working in the latest dev. I think support is limited to (field=value), but that accomplishes a lot.

I would also recommend taking a look at the new PageTable fieldType. Apparently it now has support for multiple templates, so you might be able to accomplish what you need without the overhead of repeaters.

Hi Renobird.

I just upgraded the site in question to 2.4 but obviously not the latest dev as the dependencies aren't saving so I'll go grab it and see what happens. :)

As for the PageTable, I love the idea but it came too late for this site. Converting it over would be monumental at this point so I'll look at it for the next project.

Link to comment
Share on other sites

It's strange. I updated to 2.4.3 which is the latest I could find dl'd today from the dev branch, and the checkbox field I have in the repeater with dependencies applied did not save. What am I doing wrong?

I used a simple field=value and it works until you click save.

Link to comment
Share on other sites

  • 5 months later...
...

however, processwire isn't saving that setting and so it ignores it.

I'm on PW 2.4.0

hi,

can this be an issue in 2.5.8 again? I have exactly the same behavior in a repeater which has dependencies from page-fields and url-field on another page-field.

thanks, martin

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
 Share

×
×
  • Create New...