The look up wizard is an excellent way of entering data requiring set values.
I've recently needed a look up wizard using a checkbox list where some options are implied by others. Having all the combinations as separate checkboxes would be unwieldly for both the user and me as programmer.
My first attempt simply added the associated values at the and of the array, but this upset the PHPR code supporting it causing subsequent changes to the same field to behave strangely, such as the wrong options being selected.
I just happened to notice that the values arrays had numeric keys, and that the keys, although not linear, would always be in the same order as the defined field display order. Further experimentation also showed that the key values did not always exactly match the defined field display order.
Penny dropped! The order of the selected values and the defined field display order need to be the same.
My lookup wizard maps onto this view
SELECT
TrophyCode,
TrophyName,
TopN,
HonoursOnly,
`Desc`,
HonoursOnly*100 + ifnull(EventID,0) as DisplayOrder
FROM ineligibletrophycodes
WHERE (TopN != 0) OR (HonoursOnly =true)
TrophyCode is the linked field, and DisplayOrder the display order (obviously - shame PHPR insists on a single field for the display order).
In this example, where EventID is NULL, the TrophyCode implies all other trophy codes for the same combination of TopN and HonoursOnly. Thus selecting the corresponding entry should cause all the others to be selected. Deselecting a TrophyCode for a particular event would force the 'AllEvents' trophy code to be deselected. etc etc.
Adding the following code at the end of the change field event server code fixed the strange behaviour
$result['newvalue']=array();
$rs=CustomQuery("select TrophyCode from ineligibletrophycodes where TrophyCode in ('".implode("','",$newlist)."') ORDER BY HonoursOnly,ifnull(EventID,0);");
while ($data=db_fetch_array($rs)) {
$result['newvalue'][]=$data['TrophyCode'];
}
This together with setting this.defaultValue to the new value at the end of the Client After change field event code such that each change can be monitored gives the look up wizard sensible behaviour.
Voila!