Problems with ToscaWidget2 and AjaxForm

35 views
Skip to first unread message

Diego García

unread,
Mar 20, 2014, 3:37:06 PM3/20/14
to turbo...@googlegroups.com

Hi all:


I am using ajax and forms toscawidgets2

following the example of documentation I'm trying to adapt at toscawidget2. My code is as follows:

-------------------------------------------------------------------------------------------------------------------------------
# -*- coding: utf-8 -*-
import tw2.core as twc
import tw2.forms as twf
from formencode import validators
from tgext.ajaxforms import ajaxloaded

@ajaxloaded
class TestForm(twf.TableForm):
     class child(twf.TableLayout):
        name = twf.TextField('Name', validator=validators.String(not_empty=True))
        surname = twf.TextField('Surname', validator=validators.String(not_empty=True))
    ajaxurl = '/form_show'
    action = '/form_submit'
    submit_text = "GO"
test_form = TestForm()

----------------------------------------------------------------------------------------------------------------------------

But  ajaxurl is not recognized  as a parameter of the form :-(

thanks for your help

Alessandro Molina

unread,
Mar 20, 2014, 4:41:34 PM3/20/14
to TurboGears .
Have you tried removing the test_form = TestForm() line and directly use TestForm?

TW2 forms do not need to be instantiated, and actually doing TestForm() will create another form class instead of instantiating it, which might collide with tgext.ajaxforms behaviour.

You should just do: TestForm.display() directly.


--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+...@googlegroups.com.
To post to this group, send email to turbo...@googlegroups.com.
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Diego García

unread,
Mar 21, 2014, 8:13:41 PM3/21/14
to turbo...@googlegroups.com
Now my form and running, but as I call it from the controller root in TurboGears 2.3.2


@ajaxloaded
class TestForm(twf.TableForm):
    class child(twf.TableLayout):
        name = twf.TextField('Name', validator=validators.String(not_empty=True))
        surname = twf.TextField('Surname', validator=validators.String(not_empty=True))
    ajaxurl = '/form_show'
    action = '/form_submit'
    submit_text = "GO"


I'm calling this way

    @expose('pruebas.templates.ajax')
    def ajax(self, *args, **kw):
        return dict(page='demo', form=TestForm)


but did not generated. If I remove the decorator @ ajaxloaded the form is generated without problem

Alessandro Molina

unread,
Mar 24, 2014, 2:40:28 PM3/24/14
to TurboGears .
Did you expose a "form_show" controller? Look at https://bitbucket.org/_amol_/tgext.ajaxforms#rst-header-showing-the-form there is a "form_show = ajaxform(test_form)" attribue declared into the RootController.


--
Reply all
Reply to author
Forward
0 new messages