Ok so I added a validator to my edit.
@turbogears.validate(form=myforms.COOL_FORM)
def cooledit(self,...):
  dict(editValues=..)

So the problem I am having is that if I use the validator decorator the form is not populated when it is first loaded. If I modify the data and submit it (submits to itself) it works correctly. If I comment out the validator decorator then I get the expected behavior of on first page visit the data is populated from the values I passed into the view from the controller. And it works fine submitting to itself. Is it frowned on to use widgets and submit to the same controller function? Or do we think there is a bug in my code?

Thanks,
lateef
On 4/8/06, Michele Cella <[EMAIL PROTECTED]> wrote:

[EMAIL PROTECTED] wrote:
> So, at the suggestion of several people on the list today, I figured
> out the basics of using form widgets. So now my little toy learning
> application (a wish list) is all widgety. Neat stuff. However, my
> design for this program relies on the same sort of new/not new status
> for the list items that the wiki20 tutorial uses to tell the "save"
> class how to handle the form data. I can't for the life of me figure
> out how to implement that sort of mechanism using the widgets. I tried
> a ton of different things, and none of them work. Any guidance would be
> appreciated.
>

As Kevin said, if what you need is passing values at display time to
your widgets that's what you can do.

Let's take the wiki20 Form:

        <form action="" method="post">
            <input type="hidden" name="pagename" py:attrs="value=pagename"/>
            <textarea name="data" py:content="data" rows="10" cols="60"/>
            <input type="submit" name="submit" value="Save"/>
        </form>

In Widgets language :D this becomes something like:

       class MyFields(WidgetsList):
             name = HiddenField()
            data = "">
       wiki20_form = TableForm(name="page", fields=MyFields(),
                                                 action=""
submit_text="Save")

Now if you problem is passing a value to the hidden field, that's what
you will do from your edit method (for example):

      @turbogears.expose(html="wiki20.templates.edit ")
      def edit(self, pagename):
           page = Page.byPagename(pagename)
           form_values = dict(name=page.pagename, data="">           return dict(form=wiki20_form, form_values=form_values)

in your edit.kid page you will need to do this then:

            form.display(value=form_values)

One thing to keep in mind, if you're using a CompoundFormField (ATM a
FieldSet for example) it means you are using a nested field, the value
you get as input associated to such a field is not a plain value but a
dictionary containing its field, value pair.

For example:

          class NestedFields(WidgetsList):
              
              two = TextField()

          class MyFields(WidgetsList):
              name = TextField()
              nested = FieldSet(fields=NestedFields())

          myform = TableForm(fields=MyFields(), action=""

your save method needs to be something like this:

          def save(self, name, nested):

The basic rule is that you just expect the parameter you've listed in
the WidgetsList class that you are passing as fields to the form
Widget, in this case fields=MyFields() so we use name and nested.

now when you submit such a  form that's what you get as input:

          name = "myname"
          nested = {"one": "hey", "two": "hello"}

the same rule applies if you need to pass dynamically computed values
to your form for the first display, so in the previous example (wiki20)
you don't pass a flat dictionary but a nested dictionary like this one:

           form_values = dict(name="michele",
                                          nested=dict( one",
two="really two"))

finally if you don't need to pass dynamically computed values of you
just want a field to always have a default value that should be used on
every first display of your form you can provide it at the widget
instantiation, for example:

        name = TextField(default="Your name here!")

Ciao
Michele




--~--~---------~--~----~------------~-------~--~----~
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