Thanks It helped me a lot

Here is the corrected code and how I use it

class MultipleHiddenFields(widgets.FormField):
     params = ['hidden']
     hidden = True
     template = """<input xmlns:py="http://purl.org/kid/ns#";
py:for="key, v in value.items()" type='hidden' value="${v}" name="$
{key}"/>"""

class FormChangePassword(widgets.TableForm):
    fields = [
        MultipleHiddenFields('context'),
        widgets.PasswordField('password', label="Password" ,
validator=validators.NotEmpty()) ,
        widgets.PasswordField('password2', label="Password (Repeat)" ,
validator=validators.NotEmpty()) ,
    ]
    validator = validators.Schema(
        chained_validators = [validators.FieldsMatch("password",
"password2"), ]
    )
    submit_text = "Change Password"

class Mailbox:

    change_password_form =
FormChangePassword(action="change_password")

    #
-----------------------------------------------------------------
    @turbogears.expose(template=".templates.mailbox")
    def index(self, email_addr, tg_errors=None, **kwargs):
        email_addr=str(email_addr)
        if tg_errors:
            print tg_errors

        password_value= { 'context' : { 'login':email_addr,
'another':'value' } }

        return dict(password_form=self.change_password_form,
password_value=password_value)

    @expose()
    @validate(form=change_password_form)
    @error_handler(index)
    def change_password(self, login, password, **kwargs):
        email_addr=str(login)
        password=str(password)
        ChangeMailboxPassword(email_addr, password)

        raise cherrypy.HTTPRedirect(turbogears.url('index',
dict(email_addr=email_addr)))


On 22 mar, 01:05, "Diez B. Roggisch" <[EMAIL PROTECTED]>
wrote:
> >> Just define a MultipleHiddenField-widget, which has an attribute "hidden" 
> >> that
> >> is True.
>
> > You mean define from scratch ?
>
> Er, yes. Like this:
>
> class MultipleHiddenFields(Widget):
>      params = ['hidden']
>      hidden = True
>
>      template = """
> <input py:for="key, v in value.items()" type='hidden' value="${v}"
> name="${key}"/>
> """
>
> Not exactly rocket science in my book.
>
>
>
> >> This widget then will be rendered by the form in the hidden-fields.
>
> >> This widget could for example expect it's value to be a dictionary, from 
> >> which
> >> it's key/value pairs it will render a hidden-input tag.
>
> > using jsonify for example ?
>
> >> Easy as cake...
>
> > Heuu, I'm not pastry chef
>
> >> And you can set the value for that either on rendering time, via
>
> >> ${form.display(dict=(context_fields=context_fields))}
>
> >> where context_fields is that dict of yours, or if you have to, you could
> >> create a property in the widget instead, which can of course have a 
> >> callable
> >> passed.
>
> >> This callable could extract that context information, from e.g.
> >> cherrypy.request..
>
> > Yes I this could match my need, but...
> >> Get creative!! It's all there :)
>
> > ... Creative ? What about my idea to redefine the Form class ?
> > It's a lot esyer to use, just need to mix form data and contextual
> > data together.
>
> I don't think it is easier to use, because the multiple hidden fields
> widget can be used in any form, whereas your idea requires every form to
> be aware of context.
>
> Diez


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to