El 22/11/13 21:39, John Fabiani escribió:
On 11/22/2013 02:45 PM, Ricardo Aráoz wrote:
I'm learning to work with the datanav.
I'm modifying one of the CRUDs created by the AppWizard. My file has
a foreign key that I wish the user to see as a drop down list, so I
change the input control to a dDropdownList with ValueMode='Key'. I
would usually set right there the Choices and Keys, and get done with
it. But this control must be different, if a value has already been
referenced by a foreign key in some other row of the actual table it
must not appear in the drop down, unless it is the value that is
being referenced in the actual row.
To make it easier to understand, the Choices and Keys of the drop
down list must come from the following :
crs.execute("""select Id, trim(Nombre||" "||Apellido) as
FullName
from persona
where Id not in (select PersonaId
from proveedor)
or Id = ?
order by FullName""",
(self.Record.Id , ))
where self.Record.Id is the actual row.
I have everything set and working but I am not being able to place
Choices and Keys assignment in a proper place. I've tried binding the
RowNumChanged event to the method that sets the Choices and Keys, but
this event occurs AFTER the controls are updated, so when I move the
pointer I get a value error when the framework tries to set the drop
down's Value to a foreign key that does not exist the actual choices
(the choices appropriate for the previous record).
I've also tried binding the drop down's Update event to this method
with the same results.
Has anybody done something similar? Any suggestions?
I've had this problem a lot. I want some action to occur, in
sequence, that responds to an event. I needed the data to change for
a dropdown whenever the state changed in a different dropdown (listed
all the states). There is a tutorial of some sort on the Dabo website
but it didn't work for me. What I ended up doing was playing with
"dabo.ui.callAfterInterval" and the "dabo.ui.callAfter" methods and
between the two was able to force the order of the actions. I tried
setting up a main form method to control the order of actions but that
only partially worked. My best suggestion is to work what I suggested
and see if you get the order and timing to satisfy your needs.
Other's may have had better results.
Done!
For future reference :
- in PagEditYourTable.py, class PagEditFileName(), method createItems().
Replace the dabo.ui.dTextBox that refers to your field with a
dabo.ui.dDropDownList control:
objectRef = dabo.ui.dDropdownList(self, NameBase="fldName",
DataSource="fileName", DataField="fldName",
ValueMode='Key', RegID='DropdnFldName',
ToolTipText=biz.getColToolTip("fldName"),
HelpText=biz.getColHelpText("fldName"))
Now if you just want a simple drop down list you write :
objectRef.Choices, objectRef.Keys = biz.getFldName()
Where getFldName is a method you wrote in your Bizobj, e.g.:
def getFldName(self):
crs = self.getTempCursor()
crs.execute("""select Id, fldName
from fileName
order by fldName""")
ds = crs.getDataSet()
Choices = ['None'] + [reg['fldName'] for reg in ds]
Keys = [None] + [reg['Id'] for reg in ds]
return (Choices, Keys)
- But if you need your list to change with every different row you add
to FrmFileName.py, class FrmFileName() :
def afterInitAll(self):
self.bindEvent(dEvents.RowNavigation, self.actDropdnFldName)
def afterRequery(self):
self.actDropdnPersonaId(1)
def actDropdnFldName(self, evt):
biz = self.getBizobj()
dropDn = self.DropdnFldName
dropDn.Choices, dropDn.Keys = biz.getFldName()
And of course your biz.getFldName() method will be dependent on the
values of self.Record.WhateverField.
Note: in the afterRequery() method I'm calling
self.actDropdnPersonaId(1), the "1" is just a placeholder for the event
object that is sent when the RowNavigation event calls the method.
HTH
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/[email protected]