Thanks Massimo for looking into this. I tried your suggestion but it's not working as I expected. The 'v' field selection sub-list remains empty; query is not triggered by the 't' selection since these field selections are in the same form.
It can be forced to work by selecting a 't' and then hit submit, I will get an error message and the 'v' list gets populated with the right records. Is there a way to access the user selection from a form that hasn't been submitted yet? I think I can only get request.vars.t after the user hits the submit button. /r Nik On Mar 11, 12:11 am, Massimo Di Pierro <massimo.dipie...@gmail.com> wrote: > Two things: > > 1) > do not do: > t_list = gdb(gdb.select(gdb.t_table.code, gdb.t_table.name)) > Field('t', requires = [IS_NOT_EMPTY(), IS_IN_SET(t_list)]) > > instead fo > > Field('t', requires = IS_IN_DB(gdb,'t_table.code','%(name)s')) > > 2) for v you can do > > Field('v', requires = IS_IN_DB(gdb(query),'v_table.code','%(name)s')) > where query depends on request.vars.t > > On Mar 9, 7:25 pm, Nik <nikolai...@gmail.com> wrote: > > > > > > > > > i need to validate a field based on an external read-only database (i > > call it gdb) > > > there are four tables that are related by their own codes > > gdb.r_table.code > > gdb.p_table.code > > gdb.t_table.code > > gdb.v_table.code > > > I have no use for the the id field of each table. Each table has, > > among others: > > r_table.code is unique but r_table.name may not be so. > > p_table.code is unique but p_table.name may not be. > > t_table.code is uniquely composed of r_table.code + p_table.code. > > t_table.name may not be unique. > > v_table-code is uniquely composed of t.table-code+serial numbers > > v_table.name may not be unique. > > > In my app database, I only need to store the v_table-code since I can > > programatically find out what the other codes are from it. But for the > > convenience of the user (who is probably unaware of the codes), I need > > to present a selection list of v_table.names based on choices they > > made from p_table.name and t_table.name. There are 100 records in > > p_table, 1,500 in t_table and 40,000 in v_table. > > > What's the best way to do this? > > > I thought that I could populate a variable with the list of each > > p_list = gdb(gdb.select(gdb.p_table.code, gdb.p_table_name)) > > t_list = gdb(gdb.select(gdb.t_table.code, gdb.t_table_name)) > > v_list = gdb(gdb.select(gdb.v_table.code, gdb.v_table_name)) # prolly > > not a good idea to retrieve all 40,000 but .... > > > then in the requires argument of each field > > form = SQLFORM.factory( > > # snip. other fields here > > > Field('p', requires = [IS_NOT_EMPTY(), IS_IN_SET(p_list)), # this > > works > > Field('t', requires = [IS_NOT_EMPTY(), IS_IN_SET(t_list)), # how to > > trigger controller to present a sublist of t_list > > Field('v', requires = [IS_NOT_EMPTY(), IS_IN_SET(v_list)) # how to > > trigger controller to present a sublist of v_list > > > # snip. other fields here) > > > Above works but no validation is enforced. (i.e. a user can select a > > 'v' that is not actually a member of his/her 't' selection) > > How can i trigger a controller that will filter t_list based on > > selection made on 'p' field, and another controller to do the same for > > v_list based on 'T' selection from t_list. > > > thanks.