Hi all,
In my old Access-based applications, I have many form fields that allow data selection through drop down lists tied to a background table, basically just like we do with Comboboxes and valuelists. In addition, if the entry that a user wants isn’t in the list, they can double-click on the field, which opens a dialog that allows them to add to the list (and the background table).
Now, in Servoy, I’ve set up fields as comboboxes, and attached valuelists to them. In order to let the user add new items that aren’t in the valuelist, I’m trying to build a generic procedure that will…
- Figure out what form it is in
- Figure out what field it is in
- Figure out what value list is tied to the field
- Figure out what table is tied to the value list
- Figure out what field in the table is tied to the value list
- Create a foundset for the table and add the item to it.
So far…
I’ve created fields as combo boxes with valuelists tied to them. There are a variety of value lists.
I’ve set up the field as “editable” to allow them to type in a new entry.
The onDataChange fires, and I can create a foundset based on the table attached to the valuelist to make sure that the entry isn’t already in the table (it might also be possible to just interrogate the valuelist entries, but I’m not sure how to do that).
If they want to add it, I can create a new record in the foundset, put the new data into it, and save it.
So, I can do this for an individual field without any problems.
As far as creating the global/generic version of this…
I’ve found that I can use controller.getName() to determine what form I’m on.
I haven’t been able to figure out how to determine what field I’m on. I was thinking of looking to see what field has focus, but while I can find methods to set focus. I haven’t yet found a way to ask what field currently has focus. From another entry in the Forum, I have found that while the user will need to leave the field in order to have the onDataChange fire, the field doesn’t actually lose focus until the onDataChange returns. But, I’m not sure if using focus is the right way to do this.
Once I figure out the field, I should be able to use the “valuelist” property of the field to see what valuelist is being used.
Once I figure out the valuelist, I should be able to use the “tableName” property of the value list to see what table is being used.
I haven’t yet figured out how to see what field on the table is being used to fill the value list, but I’m thinking, perhaps, getDisplayDataProviderIds.
Any thoughts on this?
As always, thanks for your assistance.
Ron