I have a problem using depselect, or the lookup widget in the following circumstances:
1. Creating a new record
2. The key field for the lookup is a relationship field that is passed from the parent record.
To be specific, I have a table called 'applicant' which contains records for people. There are two other tables called 'grants' and 'payment'. A grant is linked to an applicant using the a_id applicant id field. Similarly a payment is linked to an applicant using the same a_id applicant id field.
Finally, each payment is further associated with a grant through the g_id grant id field. All these relationships are set up and work well. No problems so far.
The problem comes in the 'New Payment' form. This form is already linked to the Applicant and has the a_id ($a_id) field set by that linkage. You then have to select the grant id to assign the payment to, this has to be a grant that is to the same applicant, I.e. the a_id fields must again be the same. I'm using the following depselect in the payment fields.ini:
[g_id]
widget:type=depselect
widget:table=grants
widget:filters:a_id='$a_id'
widget:keycol=g_id
widget:labelcol=g_description
widget:label="Grant Description"
visibility:list = hidden
visibility:browse = hidden
This should list all grants that are linked to that Applicant through the a_id field which is common to all tables by filtering the grants table on a_id = "$a_id"
This works as expected when editing an existing payment, however the select list is empty when creating a new payment. It appears that the filter isn't picking up the value of $a_id.
(I get a similar problem if I try and use the lookup widget, or even if I try and use a __sql__ command.)
Is there a problem with picking up the current value of the variable $a_id when it is the variable used to link two tables together (and is thus fixed and uneditable)? Perhaps it doesn't exist until after the record is saved?
Thanks