[Zope3-checkins] SVN: Zope3/branches/3.2/ backported missing
zope.formlib bugfixes from 3.3 branch (r68015:70426):
Yvo Schubbe
y.2006_ at wcm-solutions.de
Thu Sep 28 15:40:35 EDT 2006
Log message for revision 70427:
backported missing zope.formlib bugfixes from 3.3 branch (r68015:70426):
r68297, r68767, r69650, r69764
Changed:
U Zope3/branches/3.2/doc/CHANGES.txt
U Zope3/branches/3.2/src/zope/formlib/configure.zcml
A Zope3/branches/3.2/src/zope/formlib/errors.py
A Zope3/branches/3.2/src/zope/formlib/errors.txt
U Zope3/branches/3.2/src/zope/formlib/form.py
U Zope3/branches/3.2/src/zope/formlib/form.txt
A Zope3/branches/3.2/src/zope/formlib/ftests.py
U Zope3/branches/3.2/src/zope/formlib/pageform.pt
U Zope3/branches/3.2/src/zope/formlib/subpageform.pt
U Zope3/branches/3.2/src/zope/formlib/tests.py
-=-
Modified: Zope3/branches/3.2/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.2/doc/CHANGES.txt 2006-09-28 18:26:32 UTC (rev 70426)
+++ Zope3/branches/3.2/doc/CHANGES.txt 2006-09-28 19:40:34 UTC (rev 70427)
@@ -10,6 +10,21 @@
Bug fixes
+ - Fixed issue 691: make formlib javascript to display help texts more
+ robust. It can now also display the helptext correctly if a complex
+ widget with multiple fields and/or fields with the widget name used as
+ a prefix for the form elements is shown.
+
+ - Fixed issue 690: removed a javascript call from formlib/pageform.pt
+ which depended on a non-existent function. It was a holdover from when
+ the library was an external project.
+
+ - Fixed issue 599: Provided a view for interface.exceptions.Invalid to
+ allow formlib to display errors when validating invariants.
+
+ - Fix get_rendered in zope.formlib. Make use of get_rendered in
+ setUpInputWidget which is used in AddFormBase.
+
- Fixed error handling in sequence item input widget. This widget
was raising a ValidationError instead a WidgetInputError. The formlib
didn't catch ValidationErrors. Added also ValidationError handling to
Modified: Zope3/branches/3.2/src/zope/formlib/configure.zcml
===================================================================
--- Zope3/branches/3.2/src/zope/formlib/configure.zcml 2006-09-28 18:26:32 UTC (rev 70426)
+++ Zope3/branches/3.2/src/zope/formlib/configure.zcml 2006-09-28 19:40:34 UTC (rev 70427)
@@ -17,5 +17,13 @@
name="template"
/>
+ <!-- Error view for 'Invalid' -->
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.interface.exceptions.Invalid"
+ provides="zope.app.form.browser.interfaces.IWidgetInputErrorView"
+ factory=".errors.InvalidErrorView"
+ permission="zope.Public"
+ />
</configure>
Copied: Zope3/branches/3.2/src/zope/formlib/errors.py (from rev 68767, Zope3/branches/3.3/src/zope/formlib/errors.py)
Copied: Zope3/branches/3.2/src/zope/formlib/errors.txt (from rev 68767, Zope3/branches/3.3/src/zope/formlib/errors.txt)
Modified: Zope3/branches/3.2/src/zope/formlib/form.py
===================================================================
--- Zope3/branches/3.2/src/zope/formlib/form.py 2006-09-28 18:26:32 UTC (rev 70426)
+++ Zope3/branches/3.2/src/zope/formlib/form.py 2006-09-28 19:40:34 UTC (rev 70427)
@@ -277,7 +277,7 @@
return Widgets(widgets, len(form_prefix)+1)
def setUpInputWidgets(form_fields, form_prefix, context, request,
- ignore_request=False):
+ form=None, ignore_request=False):
widgets = []
for form_field in form_fields:
field = form_field.field.bind(context)
@@ -290,7 +290,10 @@
widget.setPrefix(prefix)
if ignore_request:
- value = field.default
+ if form_field.get_rendered is not None:
+ value = form_field.get_rendered(form)
+ else:
+ value = field.default
widget.setRenderedValue(value)
widgets.append((True, widget))
Modified: Zope3/branches/3.2/src/zope/formlib/form.txt
===================================================================
--- Zope3/branches/3.2/src/zope/formlib/form.txt 2006-09-28 18:26:32 UTC (rev 70426)
+++ Zope3/branches/3.2/src/zope/formlib/form.txt 2006-09-28 19:40:34 UTC (rev 70427)
@@ -1528,6 +1528,37 @@
size="10" type="text" value="100.0" />
<span class="dateTime">2002 12 2 12:30:00 </span>
+Now try the same with the AddFormBase which uses a setUpInputWidget:
+
+ >>> class MyAddForm(form.AddFormBase):
+ ... actions = ()
+ ...
+ ... def now(self):
+ ... return datetime.datetime(2002, 12, 2, 12, 30)
+ ...
+ ... form_fields = form.Fields(
+ ... form.Fields(IOrder).omit('now'),
+ ... form.Field(IOrder['now'], get_rendered=now),
+ ... )
+ ...
+ ... def setUpWidgets(self, ignore_request=True):
+ ... super(MyAddForm, self).setUpWidgets(ignore_request)
+
+ >>> print MyAddForm(None, request)() # doctest: +NORMALIZE_WHITESPACE
+ <input class="textType" id="form.identifier" name="form.identifier"
+ size="10" type="text" value="" />
+ <input class="textType" id="form.name" name="form.name" size="20"
+ type="text" value="" />
+ <input class="textType" id="form.min_size" name="form.min_size"
+ size="10" type="text" value="" />
+ <input class="textType" id="form.max_size" name="form.max_size"
+ size="10" type="text" value="" />
+ <input class="textType" id="form.now" name="form.now" size="20"
+ type="text" value="2002-12-02 12:30:00" />
+
+Note that a EditForm can't make use of a get_rendered method. The get_rendered
+method does only set initial values.
+
Note that the function passed must take a form as an argument. The
`setUpWidgets` function takes an optional 'form' argument, which
**must** be passed if any fields use the get_rendered option. The
Copied: Zope3/branches/3.2/src/zope/formlib/ftests.py (from rev 68767, Zope3/branches/3.3/src/zope/formlib/ftests.py)
Modified: Zope3/branches/3.2/src/zope/formlib/pageform.pt
===================================================================
--- Zope3/branches/3.2/src/zope/formlib/pageform.pt 2006-09-28 18:26:32 UTC (rev 70426)
+++ Zope3/branches/3.2/src/zope/formlib/pageform.pt 2006-09-28 19:40:34 UTC (rev 70427)
@@ -17,18 +17,9 @@
function toggleFormFieldHelp(ob,state) {
// ob is the label element
- var field = ob.form[ob.htmlFor];
+ var field = findWidgetDiv(ob);
if (field) {
- var viz = state && 'hidden' || 'visible';
- if (field.length == null) {
- field.style.visibility = viz;
- }
- else {
- for (var i = 0; i < field.length; ++i) {
- var e = field.item(i);
- e.style.visibility = viz;
- }
- }
+ field.style.visibility = state && 'hidden' || 'visible';
var help = document.getElementById("field-help-for-" + ob.htmlFor);
if (help) {
help.style.visibility = state && 'visible' || 'hidden';
@@ -36,6 +27,31 @@
}
}
+function findWidgetDiv(label) {
+ var element = findFormField(label);
+ while (element) {
+ element = element.parentNode;
+ if (element.tagName == 'DIV' && element.getAttribute('class') == 'widget')
+ return element;
+ }
+}
+
+function findFormField(label) {
+ var name = label.htmlFor;
+ var field = label.form[name];
+ // Multiple fields with the same name, such as radiobuttons
+ if (field) {
+ if (field.length)
+ field = field[0];
+ return field;
+ }
+ // No field with the exact name; find one that starts with the name
+ for (var i = 0; field = label.form[i++];) {
+ if (field.name.substr(0, name.length) == name)
+ return field;
+ }
+}
+
//-->
</script>
@@ -139,9 +155,6 @@
</div>
</form>
-<script type="text/javascript" metal:define-slot="trackChanges">
- zc_trackChanges(document.getElementById('zc.page.browser_form'));
-</script>
<script type="text/javascript"
tal:define="extra_script view/extra_script | nothing"
Modified: Zope3/branches/3.2/src/zope/formlib/subpageform.pt
===================================================================
--- Zope3/branches/3.2/src/zope/formlib/subpageform.pt 2006-09-28 18:26:32 UTC (rev 70426)
+++ Zope3/branches/3.2/src/zope/formlib/subpageform.pt 2006-09-28 19:40:34 UTC (rev 70427)
@@ -5,25 +5,41 @@
function toggleFormFieldHelp(ob,state) {
// ob is the label element
- var field = ob.form[ob.htmlFor];
+ var field = findWidgetDiv(ob);
if (field) {
- var viz = state && 'hidden' || 'visible';
- if (field.length == null) {
- field.style.visibility = viz;
- }
- else {
- for (var i = 0; i < field.length; ++i) {
- var e = field.item(i);
- e.style.visibility = viz;
- }
- }
- var help = document.getElementById("field-help-for-" + field.name);
+ field.style.visibility = state && 'hidden' || 'visible';
+ var help = document.getElementById("field-help-for-" + ob.htmlFor);
if (help) {
help.style.visibility = state && 'visible' || 'hidden';
}
}
}
+function findWidgetDiv(label) {
+ var element = findFormField(label);
+ while (element) {
+ element = element.parentNode;
+ if (element.tagName == 'DIV' && element.getAttribute('class') == 'widget')
+ return element;
+ }
+}
+
+function findFormField(label) {
+ var name = label.htmlFor;
+ var field = label.form[name];
+ // Multiple fields with the same name, such as radiobuttons
+ if (field) {
+ if (field.length)
+ field = field[0];
+ return field;
+ }
+ // No field with the exact name; find one that starts with the name
+ for (var i = 0; field = label.form[i++];) {
+ if (field.name.substr(0, name.length) == name)
+ return field;
+ }
+}
+
//-->
</script>
Modified: Zope3/branches/3.2/src/zope/formlib/tests.py
===================================================================
--- Zope3/branches/3.2/src/zope/formlib/tests.py 2006-09-28 18:26:32 UTC (rev 70426)
+++ Zope3/branches/3.2/src/zope/formlib/tests.py 2006-09-28 19:40:34 UTC (rev 70427)
@@ -125,6 +125,13 @@
zope.app.form.interfaces.IDisplayWidget,
)
component.provideAdapter(
+ zope.app.form.browser.DatetimeWidget,
+ [zope.schema.interfaces.IDatetime,
+ zope.publisher.interfaces.browser.IBrowserRequest,
+ ],
+ zope.app.form.interfaces.IInputWidget,
+ )
+ component.provideAdapter(
zope.app.form.browser.exception.WidgetInputErrorView,
[zope.app.form.interfaces.IWidgetInputError,
zope.publisher.interfaces.browser.IBrowserRequest,
@@ -507,6 +514,8 @@
'namedtemplate.txt',
setUp=pageSetUp, tearDown=placelesssetup.tearDown,
),
+ doctest.DocTestSuite(
+ 'zope.formlib.errors')
))
if __name__ == '__main__':
More information about the Zope3-Checkins
mailing list