dabo Commit
Revision 4698
Date: 2008-11-21 08:16:33 -0800 (Fri, 21 Nov 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4698

Changed:
U   trunk/dabo/ui/dControlMixinBase.py
U   trunk/dabo/ui/dDataControlMixinBase.py

Log:
Changed the field validation so that it is triggered by any call to 
flushValue(). Previously it only fired on LostFocus events, meaning that you 
could set the Value directly in code without validation.

Fixed the call to activeControlValid() to only be made if there is an active 
control, and it's not the current control.


Diff:
Modified: trunk/dabo/ui/dControlMixinBase.py
===================================================================
--- trunk/dabo/ui/dControlMixinBase.py  2008-11-20 22:43:01 UTC (rev 4697)
+++ trunk/dabo/ui/dControlMixinBase.py  2008-11-21 16:16:33 UTC (rev 4698)
@@ -16,8 +16,10 @@
 
        def __onGotFocus(self, evt):
                if self.Form:
-                       self.Form.activeControlValid()  ## make sure prior 
control's value has been flushed.
-                       self.Form._activeControl = self
+                       sfac = self.Form.ActiveControl
+                       if sfac is not None and sfac is not self:
+                               self.Form.activeControlValid()  ## make sure 
prior control's value has been flushed.
+                               self.Form._activeControl = self
                if self.Parent:
                        self.Parent._activeControl = self
 

Modified: trunk/dabo/ui/dDataControlMixinBase.py
===================================================================
--- trunk/dabo/ui/dDataControlMixinBase.py      2008-11-20 22:43:01 UTC (rev 
4697)
+++ trunk/dabo/ui/dDataControlMixinBase.py      2008-11-21 16:16:33 UTC (rev 
4698)
@@ -13,7 +13,7 @@
 class dDataControlMixinBase(dabo.ui.dControlMixin):
        """ Provide common functionality for the data-aware controls."""
        def __init__(self, *args, **kwargs):
-               self._inFldValid = False
+               self._fldValidFailed = False
                self.__src = self._srcIsBizobj = self._srcIsInstanceMethod = 
None
                self._designerMode = None
                self._oldVal = None
@@ -50,13 +50,15 @@
 
 
        def __onLostFocus(self, evt):
-               self._lostFocus()
+               if not self._lostFocus():
+                       evt.stop()
 
 
        def _gotFocus(self):
                # self._oldVal will be compared to self.Value in flushValue()
-               if not self._inFldValid:
+               if not self._fldValidFailed:
                        self._oldVal = self.Value
+               self._fldValidFailed = False
                try:
                        if self.SelectOnEntry:
                                self.selectAll()
@@ -66,20 +68,10 @@
 
 
        def _lostFocus(self):
-               ok = True
-               if self._inFldValid or (self._oldVal != self.Value):
-                       # Call the field-level validation if indicated.
-                       if hasattr(self.Form, "validateField"):
-                               ok = self.Form.validateField(self)
-               if not ok:
-                       # If validation fails, don't write the value to the 
source. Also,
-                       # flag this field so that the gotFocus() doesn't set 
_oldVal
-                       # to the invalid value.
-                       self._inFldValid = True
-               else:
-                       # Everything's hunky dory; push the value to the 
DataSource.
-                       self.flushValue()
-                       self._inFldValid = False
+               if not self.flushValue():
+                       # Field validation failed
+                       self._fldValidFailed = True                     
+                       return False
                try:
                        if self.SelectOnEntry:
                                self.selectNone()
@@ -170,7 +162,13 @@
 
 
        def flushValue(self):
-               """ Save any changes to the underlying source field."""
+               """ Save any changes to the underlying source field. First 
check to make sure
+               that any changes are validated.
+               """
+               if (self._oldVal != self.Value) and hasattr(self.Form, 
"validateField"):
+                       if not self.Form.validateField(self):
+                               # Validation failed; the form will handle 
notifying the user
+                               return False
                curVal = self.Value
                ret = None
                isChanged = False
@@ -219,7 +217,7 @@
                                                        if 
isinstance(self.DataSource, basestring):
                                                                
self._srcIsInstanceMethod = False
                                                        else:
-                                                               
self._srcIsInstanceMethod = eval("type(src.%s)" % self.DataField) == 
type(self.flushValue)
+                                                               
self._srcIsInstanceMethod = callable(getattr(src, self.DataField))
                                                if self._srcIsInstanceMethod:
                                                        return
                                                if isinstance(src, basestring):




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to