Hi there,
I could not find a bugtracker for plone.app.z3cform and plone.z3cform.
I have some patches for plone.app.form:
* kss-Validate fields in groups/fieldsets:
I would like to extend Z3CFormValidation to handle groups.
At the moment the kssattr-formname is not set if has_groups is true
(macros.pt:60). This ends in bad requests for
kss_z3cform_inline_validation/validate_input because the attribute
formname is missing.
The validationview itself uses the kssattr's formname and fieldname.
That's not enough to also check all groups enough cause there can be
more than one field with the same name and the kss-command
replaceInnerHTML makes funny things with the dom.
The two ways I see are:
* include the group into kssattr-fieldname.
* include an other kssattr in a parent of the widget (e.g. the
filedset).
I implemented the latter. It doesn't change the api for css and has
to inspect on widgetset. But im uncertain if it has any siteeffects.
A patch is attached.
* Make it possible to disable tabbing in forms with groups.
Tabbing is automaticaly enabled with groups. But normal webusers can
miss the tabs or dont't understand them which leads to a frustrating
userexperience. I attached a patch that adds an optional attribute
enable_tabbing to the form. This is not very elegant but works.
* Optional disable kss-validation
I would like to add a second optional attribute enable_kss_validation
to disable the validation
* Translate Errors in kss-validation
KSSCommands don't handle i18nmessageid's. We have to translate them
before calling core.replaceInnerHTML. A patch is attached.
* What happend to the IAdding-View? I need it for plones contentmenu.
plone.z3cform.add was removed shortly before I checked
out plone.z3cform. Didn't know there had been some code I hacked
together almost the same solution mixed from
plone.app.content.browser.adding and Five.browser.adding with some
small additions around the context-problems, and it works for me. Are
there any specific problems or plans to support IAdding for plone
3.x?
* I tried to overwrite ploneform-macros with my own view.
Is there an easy way?
I tried to register for a more special layer interface,
plone.theme.interfaces.IDefaultPloneLayer, that inherits from
ICMFDefaultSkin, but my view isn't used.
I tried to override the registration with an overrides.zcml but
that's only picked up by five in products in the /Products-folder,
which my product isn't.
I tried to use includeOverrides but realised that it does not work
when included in my own configure.zcml.
At the end I put a *-overrides.zcml in packages-includes.
In any way I would like to dokument it somewhere for me dump plone
user.
If the patches are ok I apply them to plone.app.z3cform
..Carsten
Index: plone/app/z3cform/kss/validation.py
===================================================================
--- plone/app/z3cform/kss/validation.py (Revision 21915)
+++ plone/app/z3cform/kss/validation.py (Arbeitskopie)
@@ -14,7 +14,7 @@
"""
@kssaction
- def validate_input(self, formname, fieldname, value=None):
+ def validate_input(self, formname, fieldname, fieldset='default', value=None):
"""Given a form (view) name, a field name and the submitted
value, validate the given field.
"""
@@ -41,26 +41,35 @@
form.update()
data, errors = form.extractData()
validationError = None
- for error in errors:
- if error.widget == form.widgets[raw_fieldname]:
+ if fieldset == 'default':
+ widgets = form.widgets
+ else:
+ fieldset = int(fieldset)
+ widgets = form.groups[fieldset].widgets
+
+
+ for error in errors:
+ if error.widget == widgets.get(raw_fieldname, False):
validationError = error.message
break
# Attempt to convert the value - this will trigge validation
ksscore = self.getCommandSet('core')
kssplone = self.getCommandSet('plone')
- validate_and_issue_message(ksscore, validationError, fieldname,
+ validate_and_issue_message(ksscore, validationError, fieldname, fieldset,
kssplone)
-def validate_and_issue_message(ksscore, error, fieldname, kssplone=None):
+def validate_and_issue_message(ksscore, error, fieldname, fieldset, kssplone=None):
"""A helper method also used by the inline editing view
"""
- field_div = ksscore.getHtmlIdSelector('formfield-%s' % \
- fieldname.replace('.', '-'))
- error_box = ksscore.getCssSelector('#formfield-%s div.fieldErrorBox' % \
- fieldname.replace('.', '-'))
+ field_div = ksscore.getCssSelector('#fieldset-%s #formfield-%s' % \
+ (str(fieldset),
+ fieldname.replace('.', '-')))
+ error_box = ksscore.getCssSelector('#fieldset-%s #formfield-%s div.fieldErrorBox' % \
+ (str(fieldset),
+ fieldname.replace('.', '-')))
if error:
ksscore.replaceInnerHTML(error_box, error)
Index: plone/app/z3cform/kss/form.kss
===================================================================
--- plone/app/z3cform/kss/form.kss (Revision 21915)
+++ plone/app/z3cform/kss/form.kss (Arbeitskopie)
@@ -7,6 +7,7 @@
kss_z3cform_inline_validation-formname: kssAttr('formname', true);
kss_z3cform_inline_validation-fieldname: kssAttr('fieldname', true);
+ kss_z3cform_inline_validation-fieldset: kssAttr('fieldset', true);
kss_z3cform_inline_validation-value: currentFormVar();
kss_z3cform_inline_validation-kssSubmitForm: currentForm();
}
@@ -16,6 +17,7 @@
kss_z3cform_inline_validation-formname: kssAttr('formname', true);
kss_z3cform_inline_validation-fieldname: kssAttr('fieldname', true);
+ kss_z3cform_inline_validation-fieldset: kssAttr('fieldset', true);
kss_z3cform_inline_validation-value: currentFormVar();
kss_z3cform_inline_validation-kssSubmitForm: currentForm();
}
@@ -25,6 +27,7 @@
kss_z3cform_inline_validation-formname: kssAttr('formname', true);
kss_z3cform_inline_validation-fieldname: kssAttr('fieldname', true);
+ kss_z3cform_inline_validation-fieldset: kssAttr('fieldset', true);
kss_z3cform_inline_validation-value: currentFormVar();
kss_z3cform_inline_validation-kssSubmitForm: currentForm();
}
@@ -34,6 +37,7 @@
kss_z3cform_inline_validation-formname: kssAttr('formname', true);
kss_z3cform_inline_validation-fieldname: kssAttr('fieldname', true);
+ kss_z3cform_inline_validation-fieldset: kssAttr('fieldset', true);
kss_z3cform_inline_validation-value: currentFormVar();
kss_z3cform_inline_validation-kssSubmitForm: currentForm();
}
@@ -43,6 +47,7 @@
kss_z3cform_inline_validation-formname: kssAttr('formname', true);
kss_z3cform_inline_validation-fieldname: kssAttr('fieldname', true);
+ kss_z3cform_inline_validation-fieldset: kssAttr('fieldset', true);
kss_z3cform_inline_validation-value: currentFormVar();
kss_z3cform_inline_validation-kssSubmitForm: currentForm();
}
@@ -52,6 +57,7 @@
kss_z3cform_inline_validation-formname: kssAttr('formname', true);
kss_z3cform_inline_validation-fieldname: kssAttr('fieldname', true);
+ kss_z3cform_inline_validation-fieldset: kssAttr('fieldset', true);
kss_z3cform_inline_validation-value: currentFormVar();
kss_z3cform_inline_validation-kssSubmitForm: currentForm();
}
Index: plone/app/z3cform/macros.pt
===================================================================
--- plone/app/z3cform/macros.pt (Revision 21915)
+++ plone/app/z3cform/macros.pt (Arbeitskopie)
@@ -57,7 +57,7 @@
has_groups python:bool(groups);
show_default_label python:has_groups and default_fieldset_label or form_name;"
tal:attributes="action request/getURL; enctype view/enctype;
- class python: has_groups and 'rowlike enableUnloadProtection enableFormTabbing' or 'rowlike enableUnloadProtection kssattr-formname-%s' % view.__name__;">
+ class python: has_groups and 'rowlike enableUnloadProtection enableFormTabbing kssattr-formname-%s' % view.__name__ or 'rowlike enableUnloadProtection kssattr-formname-%s' % view.__name__;">
<input type="hidden"
name="fieldset.current"
tal:condition="has_groups"
@@ -132,9 +132,11 @@
<!-- Secondary fieldsets -->
<fieldset
+ class="kssattr-fieldset-0"
tal:condition="has_groups"
tal:repeat="group groups"
- tal:attributes="id string:fieldset-${repeat/group/index}">
+ tal:attributes="id string:fieldset-${repeat/group/index};
+ class string:kssattr-fieldset-${repeat/group/index}">
<legend tal:define="form_name group/label"
tal:condition="form_name"
Index: plone/app/z3cform/kss/validation.py
===================================================================
--- plone/app/z3cform/kss/validation.py (Revision 21915)
+++ plone/app/z3cform/kss/validation.py (Arbeitskopie)
@@ -8,7 +8,10 @@
from plone.z3cform import z2
+from zope.i18nmessageid import Message
+from Products.Five.i18n import FiveTranslationService
+
class Z3CFormValidation(PloneKSSView):
"""KSS actions for z3c form inline validation
"""
@@ -46,6 +49,12 @@
validationError = error.message
break
+ if isinstance(validationError, Message):
+ ts = FiveTranslationService()
+ validationError = ts.translate(domain=validationError.domain,
+ msgid=validationError,
+ context = self.request)
+
# Attempt to convert the value - this will trigge validation
ksscore = self.getCommandSet('core')
kssplone = self.getCommandSet('plone')
Index: plone/app/z3cform/macros.pt
===================================================================
--- plone/app/z3cform/macros.pt (Revision 21915)
+++ plone/app/z3cform/macros.pt (Arbeitskopie)
@@ -57,7 +57,7 @@
has_groups python:bool(groups);
show_default_label python:has_groups and default_fieldset_label or form_name;"
tal:attributes="action request/getURL; enctype view/enctype;
- class python: has_groups and 'rowlike enableUnloadProtection enableFormTabbing' or 'rowlike enableUnloadProtection kssattr-formname-%s' % view.__name__;">
+ class python: has_groups and 'rowlike enableUnloadProtection enableFormTabbing kssattr-formname-%s' % view.__name__ or 'rowlike enableUnloadProtection kssattr-formname-%s' % view.__name__;">
<input type="hidden"
name="fieldset.current"
tal:condition="has_groups"
Index: plone/app/z3cform/macros.pt
===================================================================
--- plone/app/z3cform/macros.pt (Revision 21915)
+++ plone/app/z3cform/macros.pt (Arbeitskopie)
@@ -55,9 +55,11 @@
form_name view/form_name | nothing;
default_fieldset_label view/default_fieldset_label | form_name;
has_groups python:bool(groups);
+ enable_tabbing python:has_groups and getattr(view, 'enable_tabbing', True);
+ tabbing_class python:enable_tabbing and 'enableFormTabbing' or '';
show_default_label python:has_groups and default_fieldset_label or form_name;"
tal:attributes="action request/getURL; enctype view/enctype;
- class python: has_groups and 'rowlike enableUnloadProtection enableFormTabbing' or 'rowlike enableUnloadProtection kssattr-formname-%s' % view.__name__;">
+ class python: 'rowlike enableUnloadProtection kssattr-formname-%s %s' % (view.__name__, tabbing_class)">
<input type="hidden"
name="fieldset.current"
tal:condition="has_groups"
_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers