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

Amigo 2019-07-11 13:19:11 +02:00
parent 034fe6688c
commit 5e56cdbb81

@ -47,7 +47,7 @@ SetRegion is quite simple, mainly because most of the work had already been done
### JavaScript - AdminForm.on(change) ### JavaScript - AdminForm.on(change)
There is another way to do this in Javascript. There's this function, the 'adminForm.on(change)' of the country field and when that event occurs, we want to execute 'getRegion'. [00:14:06](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m06s) That is done every time that field is changed. That is the extra Script that needs to be added to these two if you are going to copy this. That will execute this function which is the same function that are executed on the page load.[00:14:33](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m33s) It is not necessary to execute this because that is already been done on the page load. That is all the JavaScript that needs to be added. <<<<<<<<<<<<<<< There is another way to do this in Javascript. There's this function, the 'adminForm.on(change)' of the country field and when that event occurs, we want to execute 'getRegion'. [00:14:06](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m06s) That is done every time that field is changed. That is the extra Script that needs to be added to these two if you are going to copy this. That will execute this function which is the same function that are executed on the page load.[00:14:33](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m33s) It is not necessary to execute this because that is already been done on the page load. That is all the JavaScript that needs to be added.
### PHP - Ajax Method - Model - Controller ### PHP - Ajax Method - Model - Controller
@ -61,6 +61,4 @@ It is not necessary to add the PHP to the same Admin view, since all the Ajax me
### Filtering a Dropdown ### Filtering a Dropdown
The fields that are being focused on is this Country and this Region Field which are both custom. Tutorials had been done on how to set up a Custom Field. Just for a reminder: Open Region. In Region the button is set on true ('button="true"'). [00:18:34](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m34s) The region is selected, the view name can be dynamically updated in the description. In here(XML field definition) some PHP is done. All of this PHP may be placed in 'type_PHP_1' without adding it to the 19th placement. Every area had been used.<<<<<<<<<<<<<<< The fields that are being focused on is this Country and this Region Field which are both custom. Tutorials had been done on how to set up a Custom Field. Just for a reminder: Open Region. In Region the button is set on true ('button="true"'). [00:18:34](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m34s) The region is selected, the view name can be dynamically updated in the description. In here(XML field definition) some PHP is done. All of this PHP may be placed in 'type_PHP_1' without adding it to the 19th placement. Every area had been used.[00:19:05](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m05s) I prefer to let the code appear as it had been written and not computer-generated. Options is added, and so this is just a basic Custom field without any JavaScript in it. Everything had been done in back end Admin View, the PHP as well as the Javascript.[00:19:44](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m44s) I preferred to use this field maybe in other views with different associations. So I don't tend to use the script area maybe as one might expect. So that's quickly looking at filtering a dropdown Custom list selection via JavaScript and Ajax.[00:20:15](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m15s) If you are targeting a table of another component which you do not have control over the actual field names, it will work the same way as long as there is a field of association within the table that you like to filter, you could write that PHP, find the values and filter it.
[00:19:05](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m05s) I like making the code look as it was written and not computer-generated. Then I'm adding the options, and so this is just a simple basic custom field. There isn't even any JavaScript in here. I've done everything in back end admin view. Did the PHP as well as the Javascript. I think that is because I want to use this field maybe in other views with different [00:19:44](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m44s) association. So I don't tend to use the script area maybe as one might expect. So that's quickly looking at filtering a dropdown custom list selection via JavaScript and Ajax. If you are targeting a table of another component which you're not having the control over [00:20:15](https://www.youtube.com/watch?v=Z8FLifQOjUk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m15s) the actual field names, it will work the same way as long as there is a field of association within the table that you'd like to filter you could write that PHP. Find the values and filter it.