TOPIC: Dropdown in cascade
#1851
Dropdown in cascade 7 Months ago
Hi !!!, I want to filter states by countries. I am using Idcontrol in states and countries fields. Look at the attached file please. Someboy can I help me?. Thanks.

Hola. Quiero filtrar estados por países. Estoy usando Idcontrol en las columnas estados y países. Mire el archivo adjunto por favor. ¿Alguién puede ayudarme?. Gracias.
File Attachment:
File Name: Consulta_dropdown_in_cascade.zip
File Size: 59268
 
 
Last Edit: 2010/01/22 14:40 By isi_jca.
 
#1853
Re:Dropdown in cascade 7 Months ago
isi_jca:

If I understood you properly ...

You will need to add a method to keycontrol in std lib...

//--Add the following method at KeyControl in stdlib
SetRestrictions(r)
{
.restrictions=r
}
//--End

In order to test it do the following

//Step 1 => Add fields definitions (Obligatory if you want it to work)


//Add Field_pais_id to lib with
Code:


Field_number
{
Prompt: "Pais"
Control: (Number mask: '###,###')
Format: (Number mask: '###,###')
}

//Add Field_provincia_id to lib with 

Field_number
{
Prompt: "Provincia"
Control: (Number mask: '###,###')
Format: (Number mask: '###,###')
}


//Step 2 => Add Some test tables

Code:


Database('ensure paises (pais_id, name) key(pais_id)')
QueryDo( "insert {pais_id:1, name:'Argentina' } into paises ")
QueryDo( "insert {pais_id:2, name:'España' } into paises ")
Database('ensure provincias (provincia_id,pais_id, name) key(provincia_id) Index(pais_id, provincia_id)')
QueryDo( "insert {provincia_id: 1, pais_id:1, name:'Tucumán' } into provincias ")
QueryDo( "insert {provincia_id: 2, pais_id:1, name:'Santiago del Estero' } into provincias ")
QueryDo( "insert {provincia_id: 3, pais_id:1, name:'La Rioja' } into provincias ")
QueryDo( "insert {provincia_id: 4, pais_id:2, name:'Castilla' } into provincias ")
QueryDo( "insert {provincia_id: 5, pais_id:2, name:'Catalunya' } into provincias ")



//Step 3 => Test
Code:


Window(
Controller
{
Controls: (Vert 
(Id 'paises' 'pais_id' columns:#('name') nameField:'name' name:'paiide')
(Id 'provincias' 'provincia_id' nameField:'name' columns:#('name') name:'proide')
(Static 'demo')
)
ListRecordSelected(selectedKeys,idControlField)
{
pais_id_control = .FindControl('paiide')
provincias_id_control = .FindControl('proide')

if idControlField is 'Pais'
{

provincias_id_control.SetRestrictions('pais_id=' $ selectedKeys['pais_id'])
}
else
{
if pais_id_control.Get() is ''
{
Alert('Seleccione un pais primero/Select a country first')
provincias_id_control.Set('')
}
}

}
}
)


//Step 4 => Delete tables
Code:


Database("destroy paises")
Database("destroy provincias")

 
 
#1874
Re:Dropdown in cascade 6 Months, 4 Weeks ago
Thank you very much for your help. I have modified my library (look at attached file), but I don't know where to place ListRecordSelected(selectedKeys,idControlField) method. Somebody can I help me?.
File Attachment:
File Name: dropdown_in_cascade2.txt
File Size: 3579
 
 
#1875
Re:Dropdown in cascade 6 Months, 4 Weeks ago
the code is well placed into the controller, but you have to update the fields names from paiide to codigopais and so on. Tip: Use the Inspect() function to look at the function params i.e.

ListRecordSelected(selectedKeys,idControlField)
{
Inspect(selectedKeys)
Inspect(idControlField)
}

the inspect box should appear when the function get called (the function is an event handler like the On_xx functions,
and the event fires when something is selected in a list, in this case you have several lists and must use the parameters to find wich one triggered the event)
 
 
#1876
Re:Dropdown in cascade 6 Months, 3 Weeks ago
Thank very much!!!.