I doubt there is a solution here that would satisfly everybody.

If you do now want to display errors automatically do

    form.errors.clear()

Massimo

On Oct 7, 12:13 pm, Thadeus Burgess <[email protected]> wrote:
> I am attempting to patch web2py to allow support for custom errors in custom
> forms, so that the widgets to auto magically render the errors when using
> custom form.
>
> Desired functionality should behave such as "{{=form.custom.errors.field}}"
> and would display "<div id='field__error' class='error'>must contain a
> value!</div>"
>
> The below patch provides this functionality, however, when using regular
> form, it will not render the error div.
>
> Perhaps there is a less intrusive method? Something that will still work
> with just calling {{=form}}
>
> I would think that the new errors DIV would need to be appended to the
> components of the SQLFORM?
>
> Could someone with more knowledge of the web2py innerworkings help me with
> this?
>
> Index: gluon/html.py
> ===================================================================
> --- gluon/html.py    (revision 1258)
> +++ gluon/html.py    (working copy)
> @@ -1092,8 +1092,8 @@
>      def xml(self):
>          name = self.attributes.get('_name', None)
>          if name and hasattr(self, 'errors') and self.errors.get(name,
> None):
> -            return DIV.xml(self) + DIV(self.errors[name], _class='error',
> -                errors=None, _id='%s__error' % name).xml()
> +            return DIV.xml(self) #+ DIV(self.errors[name], _class='error',
> +              #  errors=None, _id='%s__error' % name).xml()
>          else:
>              return DIV.xml(self)
>
> Index: gluon/sqlhtml.py
> ===================================================================
> --- gluon/sqlhtml.py    (revision 1258)
> +++ gluon/sqlhtml.py    (working copy)
> @@ -756,6 +756,10 @@
>                      del self.errors[key]
>              if not self.errors:
>                  ret = True
> +
> +        self.custom.errors = Storage()
> +        for key, value in self.errors.items():
> +                self.custom.errors[key] = DIV(value, _class='error',
> errors=None, _id='%s__error' % key).xml()
>
>          requested_delete = \
>              request_vars.get(self.FIELDNAME_REQUEST_DELETE, False)
>
> -Thadeus
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to