Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Has depending fields - what is it and how do we use it View modes: 
User avatar
Certified Developer 8
Certified Developer 8
richard - 10/10/2011 11:20:04 PM
   
Has depending fields - what is it and how do we use it
Hey team

Kentico 6 is looking great!

In the form fields appearance settings there is two new fields

Has depending fields
Indicates that other parameters may be updated dynamically depending on the value of the given parameter.
Depends on another field
Indicates that the behaviour (e.g. the available selection options) of the given parameter can be affected depending on the value of some other parameter.

What are these and how do I use them in a practical application.

Cheers

Richard

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 10/19/2011 12:22:58 AM
   
RE:Has depending fields - what is it and how do we use it
Hello,

Well, these sort of flags/settings are prepared in the system for custom form controls:

http://devnet.kentico.com/docs/devguide/developing_form_controls.htm

In code of your custom form control you can access these settings and take appropriate action, for example access all fields on current form which are marked as dependent and change their values or so. Let me give you an example here. Let’s say that I have developed custom form control (similar to dropdownlist) and want to use this one for two field:

Field1
Field2

The requirement is simple: whenever value of the first one is changed, the second one should be reloaded according to selection of the first one. So, I will mark the Field1 with “Has depending fields” option and the second one Field2 with “Depends on another field” option. Keep in mind that both of the fields are using the same form control in my example. In code of the form control I can write custom code in such a way, that if the field is marked with “Has depending fields” option, I can loop through all of the other fields on the form, look for all fields where “Depends on another field” option is selected and reload them according my needs.

User avatar
Member
Member
Nesfuratu - 1/11/2012 1:50:59 AM
   
RE:Has depending fields - what is it and how do we use it
I'm still not sure how I can use this.

Say I have 3 fields.

Field1: ChainRetailer
Field2: Region
Field3: StoreName

I have all the valid values for the 3 fields stored in separate custom tables. And when I'm editing these fields in my BizForm, I'm using SQL Queries to populate them.

Depending on the ChainRetailer I've selected, the values in Region needs to be updated to a filtered list, and after a Region is selected, the StoreName values needs to be updated to another filtered list.

How would you do that using these depending fields? Or is it not meant to be used in this kind of situation? If not, do you have any suggestions of how I might be able to achieve this?

Thanks,
John.

User avatar
Member
Member
kentico_michal - 1/11/2012 2:48:11 AM
   
RE:Has depending fields - what is it and how do we use it
Hello,

Easiest option in your case would be to develop one form control which will contain three dropdown list controls. Imagine that you have 3 fields (Field1, Field2 and Field3). You will hide the Field2 and the Field3 fields and allow empty values form them.

Only the Field1 field will be visible and for this field your custom form control with three dropdownlist controls will be used.

In this case you have an option to work with these controls from one code file (custom form control). You can update any fields from code file of one form control. Take a look at this example: Developing form controls.

There is a method called GetOtherValues where you can set values for other fields.

Best regards,
Michal Legen

User avatar
Member
Member
Nesfuratu - 1/11/2012 5:53:37 PM
   
RE:Has depending fields - what is it and how do we use it
How would I attach that form control to save to 3 separate fields then? Because when you're setting up the bizform, aren't you just relating 1 single form control to a single field? How can you make it so that the form control can save to 3 separate fields?

Thanks,
John.

User avatar
Member
Member
Nesfuratu - 1/11/2012 11:54:56 PM
   
RE:Has depending fields - what is it and how do we use it
In my case, how should I set up my bizform? Do I create a single field called, "StoreOfPurchase" and set it to use my custom form control?

When I do that, obviously I'm going to show Retailer to begin with, then Region, then Store. But because I've only created a single bizform field, "StoreOfPurchase", when I save my bizform, how do I make it so that it saves the Retailer, Region and Store of Purchase in 3 separate fields? Or will I always have to rely on the final result of StoreOfPurchase and work my way back up the hierarchy to figure out the Region and Retailer?

Thanks,
John.

User avatar
Member
Member
kentico_michal - 1/12/2012 6:28:52 AM
   
RE:Has depending fields - what is it and how do we use it
Hello,

As I mentioned in the previous email, you can create 3 fields: Field1, Field2 and Field3. You will hide the Field2 and the Field3 fields (Display attribute in the editing form = false) and allow empty values form them (Allow empty value = true).

Then, you need to create a custom form control that you will use for the Field1 which will be the only visible field. However, this form control will set all fields (Field1, Field2, Field3) not just the Field1. You can take advantage of the GetOtherValues method that can be used to set values for other fields as it is described in this article: Developing form controls.

Best regards,
Michal Legen

User avatar
Member
Member
nicolas.juteau-nexun - 1/12/2012 8:36:00 AM
   
RE:Has depending fields - what is it and how do we use it
I suggest seeing this video.

Miro did a great job explaining the basics of Kentico form engine and its possibilities. I know it is a big long but defenetly worth it.