Updated 030 How to filter a list field based on association with another field (markdown)

Amigo 2019-07-11 10:02:53 +02:00
parent 651b02b1f8
commit 9a1b32a9a6

@ -31,11 +31,15 @@ First load the 'jQuery("#loading"),show);' [00:06:34](https://www.youtube.com/w
### SetRegion
Now we going to setRegion. setRegion is quite simple. Mainly because we already done most of the work with the result being returned. I'll show you the PHP that returns this result in the moment. In setRegion we would get an array, we check if the array is there, [00:09:38](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m38s) and then we append. Simply as you would with any list selection, we append the value.
SetRegion is quite simple, mainly because most of the work had already been done, with the result being returned. (It gets returned by PHP). [00:09:38](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m38s) Get an array in 'setRegion', and check if the array is there, and then 'append'. Simply as with any list selection, 'append' the value.
* ### Strings - Select_A_Region, Create_A_Region
Another thing I'm almost skipping it, this select_a_region [00:09:55](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m55s) is a JavaScript variable that I'm setting through PHP, which I'll show you in a later stage. Basically it's just a string that says that you should select the region. If there is no array returned, we just use the other variable, [00:10:21](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m21s) create_a_region which is also just a string. Over here we are going to each over the array, and we are using the id, and we checking whether the id is in regions. If it's in regions, we append the id as a value. As you remember in regions we saved the text as well as the id. [00:10:51](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m51s) And so that is how we get the text, simply adding it in there(see video). I know we could have done that in the PHP, but I felt let the browser help us with some of the lifting. We got the regions there, if it's a huge table you might want it should approach this differently. Eventually we are checking whether the id and the region ==. Since if it does we want to ensure to set region value. As your member previously [00:11:25](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m25s) we found the region value, we stored it into region. Just in case the value was set before and saved. Now the person is looking through different countries. But when you can select the country that previously was saved, we want to make sure that this previous region is also shown as the selected value. That's simply what we are doing here(jQuery(#jform_region)val(id)). Then after everything is done we again trigger this liszt:Updated. [00:11:58](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m58s) Which is the same as what was triggered there(see video). That sets the regions list again afresh. Then do we run this(see video) little bit of housekeeping which does the region button.
[00:09:55](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m55s)The 'select_a_region' is a JavaScript variable that gets set through PHP, which will be discussed at later stage. Basically it's just a string that says that the region should be selected. [00:10:21](https://www.youtube.com/watch? v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m21s) If there is no array returned, other variable should be used, the 'create_a_region' which is also just a string.
Go to 'jQuery.each(array,function(i,id){' , select 'array' and use the 'id', and check if the 'id' is in 'regions'. If it is in 'regions', append the 'id' as a value. As you remember in 'regions' the text as well as the 'id' had been saved. [00:10:51](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m51s) So that is how to get the text, simply adding it in there(see video). It could have been done in the PHP, but I felt let the browser help us with some of the lifting. There is regions, if it's a huge table it should be approached differently. Eventually it is checked whether the 'id' and the 'region' equals(id==region). Since if it does it is necessary to ensure to set the 'region' value.<<<<<
As your member previously [00:11:25](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m25s) we found the region value, we stored it into region. Just in case the value was set before and saved. Now the person is looking through different countries. But when you can select the country that previously was saved, we want to make sure that this previous region is also shown as the selected value. That's simply what we are doing here(jQuery(#jform_region)val(id)). Then after everything is done we again trigger this liszt:Updated. [00:11:58](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m58s) Which is the same as what was triggered there(see video). That sets the regions list again afresh. Then do we run this(see video) little bit of housekeeping which does the region button.
### RegionButton Correction