[Zope3-checkins] SVN: Zope3/branches/3.3/ Merge r69763 from the
trunk: fix for #691 (formlib help javascript)
Martijn Pieters
mj at zopatista.com
Thu Aug 24 10:26:53 EDT 2006
Log message for revision 69764:
Merge r69763 from the trunk: fix for #691 (formlib help javascript)
Changed:
U Zope3/branches/3.3/doc/CHANGES.txt
U Zope3/branches/3.3/src/zope/formlib/pageform.pt
U Zope3/branches/3.3/src/zope/formlib/subpageform.pt
-=-
Modified: Zope3/branches/3.3/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.3/doc/CHANGES.txt 2006-08-24 14:20:56 UTC (rev 69763)
+++ Zope3/branches/3.3/doc/CHANGES.txt 2006-08-24 14:26:52 UTC (rev 69764)
@@ -13,6 +13,11 @@
- Fixed issue 696: No display widget was registered for ISet fields with
a IChoice(IBaseVocabulary) value type.
+ - 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.
+
Zope 3.3.0b2 (2006/08/18)
New features
Modified: Zope3/branches/3.3/src/zope/formlib/pageform.pt
===================================================================
--- Zope3/branches/3.3/src/zope/formlib/pageform.pt 2006-08-24 14:20:56 UTC (rev 69763)
+++ Zope3/branches/3.3/src/zope/formlib/pageform.pt 2006-08-24 14:26:52 UTC (rev 69764)
@@ -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>
Modified: Zope3/branches/3.3/src/zope/formlib/subpageform.pt
===================================================================
--- Zope3/branches/3.3/src/zope/formlib/subpageform.pt 2006-08-24 14:20:56 UTC (rev 69763)
+++ Zope3/branches/3.3/src/zope/formlib/subpageform.pt 2006-08-24 14:26:52 UTC (rev 69764)
@@ -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>
More information about the Zope3-Checkins
mailing list