Updated 030 How to filter a list field based on association with another field (markdown)
@@ -3,13 +3,16 @@
|
||||
|
||||
### Explanation Of Filter Fields
|
||||
|
||||
Hi I don't know some of you also have encountered the reality of having sort of limit the drop downs of a list field based on it's association with another table. A very common place where we find this [00:00:22](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m22s) is for example when you want to load the regions of only one country. I'm going to show you how I have achieved this I realize there are many ways to do this and yet this is how I've done it.
|
||||
Perhaps you encountered the necessity to limit the drop downs of a list field based on it's association with another table.[00:00:22](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m22s) A very common place where this occurs, is for example, when the regions of only one country need to be loaded. Although there are many ways to accomplish this, this is how I have done it.
|
||||
|
||||
* ### Example Component With Filters
|
||||
|
||||
To start off, I have a component I could use as a illustration called job tracking. Now in this component [00:00:50](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m50s) I have a client area. Then I have already loaded, I go to admin views, you would see there is country and regions. Now I'm going to illustrate it on the basis of country and regions but you can change the field concepts and replace it with other tables. [00:01:16](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m16s) None the less this is what I'll be using. I'm going to show you how I implemented it in inside the client's view because that's where most of the work is done.
|
||||
For example: Here is a component called 'Job Tracking'. [00:00:50](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m50s)In this component is a client area. If you go to Admin Views,it may be seen that there is 'Country' and 'Regions'. It can be illustrated on the basis of Country and Regions but the field concepts can be changed and replaced it with other tables. [00:01:16](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m16s) Nonetheless this will be used. Here follows a explanation of how it is implemented in the client's view because that's where most of the work is done. JavaScript, as well as the PHP area are two areas that need to be looked at. [00:01:51](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m51s)In various previous tutorials some of the Ajax functionality in Component Builder had been explained. .
|
||||
|
||||
I'm going to look in the two places we want to look at JavaScript, as well as the php area. Now I have in various previous tutorials explain some of the Ajax functionality [00:01:51](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m51s) in component builder. I realized not all of you might have watched all the tutorial so I'll explain some of that again briefly. But having said that we first going to look at what we really want to achieve. [00:02:19](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m19s) When you start with a client, you would like to choose a country. Then have it load only that country's regions, that is what you want to do. Furthermore you want to make sure when it does that, you unselect [00:02:41](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m41s) the country, it also unselects the region. There are various things we want to achieve here. So in JavaScript I'm going to show you how I've done that. I'm just illustrating at the moment one country. Maybe I should go put on a few more, so now if I look it says Australia. If I click on Australia, [00:03:10](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m10s) you will see that it doesn't load any regions in fact that says create a region. If I choose Namibia, it says select a region, and so there's two regions already created. Now as you know by now there is this button(see video). In some of the dropdowns which are being added by saying true to the button. It's very helpful for either creating or editing existing regions. So if you could sort of selecting a country where there isn't any regions set yet, [00:03:44](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m44s) it tells you to create one. You can then create a region for this country, and what's nice if you click on this create, you can then simply create your region. Save and close. I don't know any of Australia regions, I'm just going to call it Region for now. Save and close. Go back to creating a client. [00:04:17](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m17s) If I now select Australia you will see that it's got regions. So there we go, problem solved. And that's what I'm going to demonstrate how I did that.
|
||||
For the sake of those who have not watched all the tutorials, here is a brief explanation. But first it should be determined what is our objective. [00:02:19](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m19s) When starting with a client a country needs to be selected. Then have it load only that country's regions.<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
Furthermore you want to make sure when it does that, you unselect [00:02:41](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m41s) the country, it also unselects the region. There are various things we want to achieve here. So in JavaScript I'm going to show you how I've done that. I'm just illustrating at the moment one country. Maybe I should go put on a few more, so now if I look it says Australia. If I click on Australia, [00:03:10](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m10s) you will see that it doesn't load any regions in fact that says create a region. If I choose Namibia, it says select a region, and so there's two regions already created. Now as you know by now there is this button(see video). In some of the dropdowns which are being added by saying true to the button. It's very helpful for either creating or editing existing regions. So if you could sort of selecting a country where there isn't any regions set yet, [00:03:44](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m44s) it tells you to create one. You can then create a region for this country, and what's nice if you click on this create, you can then simply create your region. Save and close. I don't know any of Australia regions, I'm just going to call it Region for now. Save and close. Go back to creating a client. [00:04:17](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m17s) If I now select Australia you will see that it's got regions. So there we go, problem solved. And that's what I'm going to demonstrate how I did that.
|
||||
|
||||
### Two Variables - Var Regions(object) Var Region(store)
|
||||
|
||||
|
Reference in New Issue
Block a user