Jump to content

Field Dependencies


ryan

Recommended Posts

Would this also work with fieldsets? That displaying a fieldsets is depended on a choice from lets say a checkbox or dropdown

Yes, it does work with Fieldsets. The first version doesn't work with tabs (FieldsetTab) though. 

I guess the selector for that would be something like user.role=editor|manager as well as user.id=41 maybe for scenarios where the main admin user wants to test some stuff or have hidden fields that other superusers can't see (though that's silly as other superusers could give themselves access anyway - just thinking of odd scenarios!).

I think this seems like a good idea Pete. I'll look into how best to implement in the next version. The first version I need to get committed to the dev source tomorrow (30th), so not planning to expand the scope of it this week, but moving forward, would like to continue expanding the dependencies system everywhere it makes sense. And your ideas here do seem like they could be very useful, and may not be very difficult to implement. 

Something to keep in mind is that dependencies are assumed to be things that can change during the course of filling out the form (i.e. if this field is populated, then this field is available, etc.). So when we get into things like user roles, we're talking about things that don't change during the course of the form. So these would be an entirely different kind of dependency. These would be dependencies that would be applicable before the form is actually rendered. They wouldn't need to be considered by the javascript dependencies at all. As a result, it really might make more sense for this capability to be something separate, at least from the code perspective.

  • Like 6
Link to comment
Share on other sites

I've gone ahead and committed the Inputfield dependencies to the dev branch, for anyone that would like to help test. I've also posted a documentation page that explains how and where to use them, current limitations and examples. There are a near infinite number of potential scenarios on how these things could be used, so it's not possible for me to test everything locally. As a result, expect bugs and please report them when you find them. Thanks in advance for your help in testing.

For non-default admin themes, some updates have to be made in order to support field dependencies. As a result, unless you are an admin theme developer, it's best to stick to the default admin theme when using field dependencies, temporarily. 

Field dependencies can also be used in FormBuilder. Though I've not done a lot of testing in FormBuilder yet, so don't recommend using field dependencies in front-end production forms just yet. Though in my initial testing, they seem to work just fine. 

Thanks again to Antti/Avoine for sponsoring field dependencies! 

  • Like 12
Link to comment
Share on other sites

I go off to build stuff, come back and get floored with new PW stuff. Man it just keeps getting better! This will be super handy on some sites I have in the queue! Looking forward to 2.4!

@Ryan Thanks for your hard work. 

A big shout out  @Avoine and @Antti!

  • Like 1
Link to comment
Share on other sites

btw..did you forget to bump dev version to 2.3.4? Still reads 2.3.3. in my install

Yep, I forgot. :) Just bumped it now, thanks.

Ryan, dependencies seems to work great on templates. But I don't seem to get it working on Form Builder preview?

I've done very little testing with FormBuilder so far. I've really been focused on getting everything stable with the page editor context, before focusing on FormBuilder context. However, what works in one InputfieldForm should work in another. I did just test in FormBuilder and it seems to be working here (testing with checkbox field). First thing to try is in your preview window, right click within it and select "reload" (and do it again just for good measure). We want to make sure it's not a result of an old cached version of inputfields.js or inputfields.css. The one used in the page editor specifies a version number, which prevents that one from being cached. Whereas FormBuilder does not, so there's a good chance that Chrome just doesn't see the changed files yet, especially given that it's in an iframe. If it's still not working, let me know the type of dependency you are doing (including the selector) or just export and email me the form JSON and I'll import here to test.

Link to comment
Share on other sites

My fieldset behave perfect, hiding with selectfieldvalue=something.

I really like that you can just say "required" for all the fields inside fieldset, and if the fieldset is hidden, then those fields inside that aren't required. Logical and powerful.

  • Like 2
Link to comment
Share on other sites

The "fieldset1_END" is there but the OPEN is gone!  :D

Ah it's there's but loosing the indent...

That's a bug! Thanks for finding it. Just fixed in latest commit. While I was in there, I updated the fields list in the template editor to display more information (labels and types). 

post-2-0-02735800-1377948028_thumb.png

This is amazing stuff Ryan! Working very well, definitely even more robust than I even imagined! I love the implementation with data attributes too.

Thanks, glad that you are liking it so far! 

  • Like 3
Link to comment
Share on other sites

When I use a showIf on with counter>0, counter<10 it doesn't work, it shows the field when the integer field is 1 and hides it again with a value of 2.

I also tested my dimension fieldtype and it got the same behaviour when I only write "dimension_width>0" it gets hidden when the value is 2.

Link to comment
Share on other sites

When I use a showIf on with counter>0, counter<10 it doesn't work, it shows the field when the integer field is 1 and hides it again with a value of 2.

Thanks for the testing. I always seem to be thinking in PHP–looks like I needed to add some parseInt()'s in there (parseFloat()'s too). This should now be fixed in the latest commit. 

I also tested my dimension fieldtype and it got the same behaviour when I only write "dimension_width>0" it gets hidden when the value is 2.

I'm curious to know if the dimension inputfield works with dependencies? I would think that it would not, given that there are multiple inputs and dependencies haven't been coded for multiple inputs on a single inputfield. But if it turns out to be working [after the last commit] that would be a nice surprise. 

Link to comment
Share on other sites

Thanks for the testing. I always seem to be thinking in PHP–looks like I needed to add some parseInt()'s in there (parseFloat()'s too). This should now be fixed in the latest commit. 

I'm curious to know if the dimension inputfield works with dependencies? I would think that it would not, given that there are multiple inputs and dependencies haven't been coded for multiple inputs on a single inputfield. But if it turns out to be working [after the last commit] that would be a nice surprise. 

Yes it does work, as the I use the input names and in dimensions inputfield I set them to "fieldname_width, fieldname_height", so this seems to work fine.

  • Like 2
Link to comment
Share on other sites

Did some testing of the beta version and noticed a few things. In my template i have a field (d_product) with type of page that holds the product pages, the selection is limited to 1 page.

Testing to show a certain field (d_nr) when the d_product page id is 1008, 1009, 1010 or 1011

This does work:

d_product>1007,d_product<1012

This does'nt work:

d_product>=1008,d_product<=1011

This also does'nt work:

d_product=1008,d_product=1009,d_product=1010,d_product=1011

This does'nt work for now as expected (described in current limitations):

d_product=1008|1009|1010|1011

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