On Friday, December 18, 2015 at 3:14:38 AM UTC-5, Alfonso Serra wrote: > > you should instead hide the errors, and then you could add your own via >> server-side DOM manipulation. >> > > But how do i do that if i dont know when errors has happened?. >
After validation, if there are errors, then you will find them in form.errors. > Currently the form gets automatic markup when is instantiated and its > modified later on when process is called. > But this is like executing the view before the controller. > Wouldnt be better to serialize the form just once, when xml() is called?, > even perfomance wise since nothings gets serialized until its droped into a > view. > The form is only serialized into HTML once -- when you do {{=form}} in the view. The server-side *DOM* of the form is created when the form is instantiated, but it is not serialized to HTML at that point. The reason the DOM is created when the form is instantiated is so validators (and other attributes) can be attached to the appropriate elements when the form is defined. This is necessary with FORM because there is no DAL model associated with the form, so the form elements themselves must store these attributes. Because SQLFORM is built on top of FORM, it uses the same mechanism. > Either i have to go back to my workaround {{=mystyle(form)}} or rearrange > the SQLFORM code so gets serialized at the end of its lifespan, like it > should, in my opinion. > The problem is not that the form gets serialized before the view is executed (it doesn't), but that the errors are added during the serialization process, so there is no opportunity to customize them (short of excluding them altogether and adding your own errors to the DOM after validation but before serialization). This should be improved. > So far ive overriden "def xml(self):" to something like > return form.custom.begin + self.createform(xfields=None) + form.custom.end > I'm not sure it's worth bothering with that. If you need completely custom markup, the {{=mystyle(form)}} solution is a reasonable approach. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.