Thanks Chris and Jorge,

It turns out that after using the magic of widgets and forms, I had
forgotten about validators (whoops). Jorge, I was able replace my
previous controller method with the following:

class MySchema(validators.Schema):
    field1 = validators.String(not_empty=True)
    checkedBoxes= validators.JSONValidator(not_empty=True)
...
# in RootController:

    @expose(format="json")
    @validate(validators=MySchema())
    def doSomething(self, field1, checkedBoxes):
        log.info("Request Headers: \n%s" %request.headers)
        # I didn't feel like writing my own validator, so I still have
to convert
        # the list elements to from strings to ints
        intList = map(int, checkedBoxes)
        return dict(results=foo(field1, intList))

Chris, formContents is a neat function, but I couldn't get it to work
for my application. The problem is that, when using the CheckBoxList
widget (http://trac.turbogears.org/browser/branches/1.0/turbogears/
widgets/forms.py#L1053), all the checkboxes have the same name.
Additionally, there seems to be an extra field included in the output
(HTML) which I, as a user of the CheckBoxList widget, seem unable to
easily disable. Here's the query string I get from running:
arr = formContents(); queryString(arr[0], arr[1]);

HTML=&field1=foo&checkedBox=0&checkedBox=1&checkedBox=2&checkedBox=4&checkedBox=9&checkedBox=11&checkedBox=13&checkedBox=17&checkedBox=18&checkedBox=24&checkedBox=25&checkedBox=29&checkedBox=36&checkedBox=41&checkedBox=42&checkedBox=45&checkedBox=46&checkedBox=51&checkedBox=53&checkedBox=54&checkedBox=55&checkedBox=58

In the end, I'm sticking with my original javascript which manually
selects the checked boxes with the document.form.checkboxElements
command (see loadMatches() above).

Thanks to you both for responding so quickly and being so helpful!
Mark

On Jul 12, 2:40 pm, Christopher Arndt <[EMAIL PROTECTED]> wrote:
> MarkThomasschrieb:
>
> > I have a small javascript function that attempts to call an exposed
> > Turbogears method expecting a Python list as an argument. The function
> > takes the array-like NodeList of checkboxes in a form and attempts to
> > send the values of the positively-checked boxes back to Turbogears.
>
> Why don't you just turn the checkbox status in to a normal query string
> and let CherryPy turn the request variables into a list value? I haven't
> tested this, but I think you could use MochiKit's "queryString" and
> "formContents" function for that:
>
> http://mochikit.com/doc/html/MochiKit/Base.html#fn-querystringhttp://mochikit.com/doc/html/MochiKit/DOM.html#fn-formcontents
>
> Chris
--~--~---------~--~----~------------~-------~--~----~
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