In this article we will learn how to use the "Ajax Processing" function available in Scriptcase. As an example, we have a control-type application with two select fields ("state" and "city"), where when we select the state we will use ajax processing to bring us, in the city field, only the cities of the state selected.
To achieve such an effect, we need to maintain some sort of relationship between our tables. In our case, the city table has a field that holds the id of its state:
Tabela adm_estados: |
Tabela adm_cidades: |
First, we need to create the control application and the two fields we will use
Next, we need to create the SQL commands of our fields, let's start with the state field. Select the field from the interface, and go to the Lookup Editing option and assemble your select, below see how we set up ours:
Query SQL - state |
SELECT EstadoID, NomeEstado FROM adm_estados ORDER BY NomeEstado |
Next, we will configure the SQL command of the city field:
Query SQL - city |
SELECT estado, cidade FROM adm_cidades WHERE state= '{state}' ORDER BY cidade |
Note that in this second we make use of a where cláusua, to filter the cities by the chosen state.
Finally, go back to the field state and look for the Ajax Processing option. Coming to it, select the Use Ajax option to reload other select, double select, radio, and checkbox fields, and then select the city field.
Run the app and see its operation: