form.custom usage

63 views
Skip to first unread message

Diogo Munaro

unread,
Oct 22, 2013, 10:16:50 AM10/22/13
to web...@googlegroups.com
Hi, I'm using custom forms because I have a predefined layout.

So, in views, if I make:

{{form.custom.begin}}

{{form.custom.widget.first_name}}

{{form.custom.submit}}
{{form.custom.end}}

The fields comes without validators. Then, it reflect problems with form.process().accepted

By now, I'm using:

{{form.custom.begin}}
{{=form.element(_name="first_name")}}

{{=form.element(_type="submit")}}
{{form.custom.end}}

I'ts works great with validators. It's ok? What's happen here?


Anthony

unread,
Oct 22, 2013, 10:33:37 AM10/22/13
to web...@googlegroups.com
{{form.custom.begin}}

{{form.custom.widget.first_name}}

{{form.custom.submit}}
{{form.custom.end}}

Is that the actual code? If so, you need to precede each item above with an "=".
 

The fields comes without validators. Then, it reflect problems with form.process().accepted

Validation happens in the controller when form.process() is called, not in the view. So you still get validation when you use form.custom.widget.
 

{{form.custom.begin}}
{{=form.element(_name="first_name")}}

form.element(_name="first_name") is the same as form.custom.widget.first_name.

Anthony

Diogo Munaro

unread,
Oct 22, 2013, 3:18:16 PM10/22/13
to web...@googlegroups.com
Sorry Antony, I forgot the = here, but the code have it.

The fields are there, but no validators work

Anthony

unread,
Oct 22, 2013, 3:31:40 PM10/22/13
to web...@googlegroups.com
Please show all of your controller and view code.

Diogo Munaro

unread,
Oct 23, 2013, 8:46:30 AM10/23/13
to web...@googlegroups.com
Now it's working only with form.element(_name="first_name").

The controller is the same for 2 types. Tomorrow I'll post everything, but now I can post the controller simple structure:

def register():
    form = SQLFORM.factory(db.person, db.auth_user,db.researcher)
    if form.process().accepted:
        ##register people in db

The view was the same... I need a auth structure with 3 tables:

People has n auth and auth has n researcher, and I really need it...

Diogo Munaro

unread,
Oct 24, 2013, 9:07:09 PM10/24/13
to web...@googlegroups.com
Here my controller and view: http://pastebin.com/AXGx99UN

If I use form.custom.widget.first_name (for example). It's doesn't work.

Another thing, if I insert:

form2.element(_name="city_id")['_type']='hidden'

after:

if form2.process().accepted:

It's returns a text field before the validation instead of a hidden field.


2013/10/23 Diogo Munaro <diogo....@gmail.com>

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/ggzIjyqNoSQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Anthony

unread,
Oct 24, 2013, 10:20:47 PM10/24/13
to web...@googlegroups.com
Not quite clear what the problem is. What you put in the view shouldn't matter -- that just generates the HTML to display the widgets -- it doesn't have anything to do with validation (and form.custom.widget.fieldname will produce the same HTML as form.element(_name='fieldname')). Of course, you won't be able to use form.custom.widget.fieldname for the fields you manually added to the form.

If you have time, perhaps you could produce a minimal app that replicates the problem. Include one page that uses form.custom.widget and one that uses form.element(), and explain how they behave differently.

Also, note that form.elements()[0][0] is simply equivalent to form[0].

Anthony

Diogo Munaro

unread,
Oct 25, 2013, 6:07:16 AM10/25/13
to web...@googlegroups.com

Thanks Anthony, I will try...
Next week I will reproduce it.

Reply all
Reply to author
Forward
0 new messages