--- a/src/pyams_form/form.py Fri Feb 01 18:35:07 2019 +0100
+++ b/src/pyams_form/form.py Thu Jul 25 12:06:22 2019 +0200
@@ -682,6 +682,33 @@
return False
+class WidgetSelector(object):
+ """Widget event selector
+
+ This selector can be used by subscribers to filter widgets events
+ """
+
+ def __init__(self, ifaces, config):
+ if not isinstance(ifaces, (list, tuple)):
+ ifaces = (ifaces,)
+ self.interfaces = ifaces
+
+ def text(self):
+ return 'widget_selector = %s' % str(self.interfaces)
+
+ phash = text
+
+ def __call__(self, event):
+ for intf in self.interfaces:
+ try:
+ if intf.providedBy(event.widget):
+ return True
+ except (AttributeError, TypeError):
+ if isinstance(event.widget, intf):
+ return True
+ return False
+
+
class ajax_config(object):
"""Class decorator used to declare AJAX settings for a form.
--- a/src/pyams_form/include.py Fri Feb 01 18:35:07 2019 +0100
+++ b/src/pyams_form/include.py Thu Jul 25 12:06:22 2019 +0200
@@ -17,7 +17,7 @@
# import interfaces
# import packages
-from pyams_form.form import FormSelector
+from pyams_form.form import FormSelector, WidgetSelector
def include_package(config):
@@ -28,6 +28,7 @@
# custom subscriber predicate
config.add_subscriber_predicate('form_selector', FormSelector)
+ config.add_subscriber_predicate('widget_selector', WidgetSelector)
# load registry components
config.scan()