Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isValidEmail validator doesn't work if field is outside default fieldset #172

Closed
fredvd opened this issue Jun 6, 2019 · 1 comment · Fixed by #177
Closed

isValidEmail validator doesn't work if field is outside default fieldset #172

fredvd opened this issue Jun 6, 2019 · 1 comment · Fixed by #177

Comments

@fredvd
Copy link
Member

fredvd commented Jun 6, 2019

The isvalidEmail validator doesn't work if you put in on a required field that is outside the default fieldset. Tested in easyform 1.x branch on Plone4 and easyform 2.1.0 on Plone 5.

isValidEmail_easyform2-1

Maybe also related to #157 where the defaut expression no longer works if the field is in a fieldset. Some actions are not run on fields in fieldsets. Also #132 relates to things not working in a fieldset

@fredvd
Copy link
Member Author

fredvd commented Jun 6, 2019

Pfew, that was a debug session for me. Found it, I think:

@implementer(IValidator)
@adapter(IEasyForm, Interface, IEasyFormForm, IField, Interface)
class FieldExtenderValidator(z3c_validator.SimpleFieldValidator):
""" z3c.form validator class for easyform fields """
def validate(self, value):
""" Validate field by TValidator """
super(FieldExtenderValidator, self).validate(value)
efield = IFieldExtender(self.field)
validators = getattr(efield, "validators", [])
if validators:
for validator in validators:
vmethod = queryUtility(IFieldValidator, name=validator)
if not vmethod:
continue
res = vmethod(value)
if res:
raise Invalid(res)
TValidator = getattr(efield, "TValidator", None)
if TValidator:
try:
cerr = get_expression(self.context, TValidator, value=value)
except Exception as e:
raise Invalid(e)
if cerr:
raise Invalid(cerr)

This FieldExtenderValidator only adapts fields directly on IEasyFormForm, which are fields in the default 'group'. But the fields in the fieldselts are in an IGroup (or actually an plone.z3cform.fieldsets.group.Group object), not an IEasyForm, so the FieldExtenderValidator is never called for fields in fieldsets.

Gonna patch the 1.x branch directly and provide a pull request with added tests for 2.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant