I knew there had to be a 'right' way of doing it! Thanks so much.

On 4/6/06, Michele Cella <[EMAIL PROTECTED] > wrote:

Hi Nicky,

You just need to return the submit_text you want to use from your
method, then in the form display do something like this:

form.display(submit_text)

Tip of the day:

If you print form.template_vars you get something like:

["action", "method", "form_attrs", "submit_text", "table_attrs"]

every attribute listed in the template_vars of a widget can be changed
by passing it at __init__ and also at display, since submit_text is
there the solution I mentioned should will work.

Hope this helps.

Ciao
Michele

[EMAIL PROTECTED] wrote:
> I have a widget based on TableForm. It is holds a simple textfield. It
> is used in two methods 'add' and 'edit'. What I want to do is change
> the submit button text depending on the method I am executing. My idea
> of changing the submit_text on the form throws an exception dealing
> with not beubg threadsafe.
>
> Here is what I did:
>
> class TagFields(widgets.WidgetsList):
>     tag = widgets.TextField(validator=validators.NotEmpty())
>
> class TagForm(widgets.TableForm):
>     name = 'tags'
>     fields = TagFields()
>     submit_text = "Add Tag"
>
> class  TagController(controllers.RootController):
>     tagform = TagForm()
>
>     @turbogears.expose(template="tgiplib.templates.tags ")
>     def edit(self,**kw):
>         #...
>         values = dict ( tag = tag.tag)
>         self.tagform.submit_text = 'Change Existing Tag'
>         return dict(
>             form= self.tagform,
>             values = values,
>             #...
>         )
>
>     @turbogears.expose(template="tgiplib.templates.tags")
>     def add(self,**kw):
>         #...
>         self.tagform.submit_text = 'Add New Tag'
>         return dict(
>             form=self.tagform,
>             values = None,
>             #...
>         )
>
> When I use this method to change the button text I get an exception
> after a good initial page load.
> ...
>   File
> "/home/nicky/lib/python2.4/site-packages/TurboGears-0.9a4-py2.4.egg/turbogears/widgets/base.py",
> line 174, in __setattr__
>     raise ValueError, \
> ValueError: It is not threadsafe to modify widgets in a request
>
> So my question is :
>
>     "How can I change the submit text of a form button at runtime?"
>
> Thanks for your help,
>
> Nick





--
--
Nicky Ayoub
G-Mail Account
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to