Forum OpenACS Q&A: How are xowiki.Formfields of type form_page specified?

I am not clear on how to populate a 'select' formfield of type form_page. As an example I will use a list of nearby hotels for an airport.

{af_hotels:optional,form_page,form=hotels,where=ht_iata_code='MCO',label=Hotels}

I want the dropdown select box to include all hotels that are associated with the airport IATA code MCO, which is one of the form fields in the form 'hotels'. How is this done?

The next step would be to replace the 'MCO' hardcoded into the form spec with the value of af_iata_code, this being the value of the IATA code in the form 'airports'.

i.e.

{af_hotels:optional,form_page,form=hotels,where=ht_iata_code=@af_iata_code@,label=Hotels}

Can this, or anything like it be done?

I see that category trees may play a part in this, but am also not clear how this is done?

Regards
Richard

A little more information.....I have now tried this:

{af_hotels:optional,form_page,form=hotels,label=Hotels}

....which works and provides an unfiltered list of hotels in the combo/dropdown box. However, why is my where clause returning no rows?

,where=ht_iata_code='MCO',

As a result I now have another question! With the above shown formfield specicifation, it is the _title field that appears in the dropdown. Is it possible to specify a different field to be displayed (i.e. in this example the IATA code field)?

In this example, it would in fact make more sense to have a selector in the 'hotels' form that allowed the selection of an airfield, instead of the other way around. However, if I do that I would want to list the ICAO codes rather than the airfield names stored in the _title field.

I hope this makes sense?

What an immensely powerful tool this is! 😊

Regards
Richard

Concerning the first question: in case the hotel form defines ht_iata_code as a text field (type text), your example should works, when you remove the single quotes around MCO.

The where clause is translated either to a tcl-based filter (fetching all instances of the form into memory and applies the filter afterwards) or - when configured - maps this into a postgres hstore query (when hstore is available in your postgres installation and the parameter use_hstore is used). The hstore stuff is currently still part of the xowf package, where fast fetching via instance attributes is necessary for larger apps (we use frequently xowf based questionnaires with several thousand participants). I am mentioning this since for the automatic query transformations, not all form field types are currently supported by the translator (this is done by the method filter_expression of FormPage).

Concerning the second question: the use of the title as label for the options was hard-wired. i've modified the code such one can use for form-field-type "form_page" the attribute "entry_label". It can be used in the form-constraints like "label" etc. Using e.g ...,entry_label=ht_iata_code,....